zk框架:如何从zul目录下的WEB-INF加载zul页面 [英] zk framework: how to load zul pages from WEB-INF under directory zul
问题描述
我正在使用 zk 框架 6.我试图将我的 zul 页面放在/WEB-INF/zul 目录中.我的 index.zul 文件将请求转发到/WEB-INF/zul/login.zul,它有一个 Composer LoginComposer.但是当我在登录页面时,我想将用户重定向到另一个页面,例如家.zul.但我收到 404 错误.
I am using zk framework 6. I am trying to put my zul pages in /WEB-INF/zul directory. My index.zul file forwards the request to /WEB-INF/zul/login.zul which has a composer LoginComposer. But when I am on login page I want to redirect the user to another page e.g. home.zul. But I am getting 404 error.
login.zul 和 home.zul 以及它们各自的作曲家都在 zul 目录中.
Both login.zul and home.zul are in zul directory along with their respective composers.
在 loginComposer.java 中,我有以下代码可以重定向到在单击按钮时调用的主页.
in loginComposer.java i have the following code to redirect to the home page which is called on a button click.
Execution exec = Executions.getCurrent();
HttpServletResponse response = (HttpServletResponse)exec.getNativeResponse();
response.sendRedirect(response.encodeRedirectURL("/WEB-INF/zul/home.zul")); //assume there is /login
exec.setVoided(true);
我将项目创建为 eclipse 的 zk 项目,但我没有对 web.xml 进行任何更改.
I created the project as a zk project from eclipse and i made no changes to web.xml.
请指导我如何离开这里.
please guide me how can i go from here.
提前致谢.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>abc</display-name>
<listener>
<description>
Used to cleanup when a session is destroyed</description>
<display-name>ZK Session cleaner</display-name>
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>
<servlet>
<description>
The ZK loader for ZUML pages</description>
<servlet-name>zkLoader</servlet-name>
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<description>
The asynchronous update engine for ZK</description>
<servlet-name>auEngine</servlet-name>
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>/zkau/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>index.zul</welcome-file>
</welcome-file-list>
</web-app>
zk.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
Created by ZK Studio
-->
<zk>
<device-config>
<device-type>ajax</device-type>
<timeout-uri>/timeout.zul</timeout-uri><!-- An empty URL can cause the browser to reload the same URL -->
</device-config>
</zk>
登录Composer.java
LoginComposer.java
public class LoginComposer extends SelectorComposer<Component>{
private static final long serialVersionUID = -1657004425904043268L;
@Wire
private Button buttontestButton;
@Listen("onClick = #testButton")
public void cancelButton(){
Executions.sendRedirect("/WEB-INF/zul/home.zul");
}
}
推荐答案
不可能
我环顾四周,发现一个德国网站解释说,规范
java-servlet 将 WEB-INF 文件夹定义为客户端不可访问,
因为它包含作为永远不应该从服务器外部访问的类的数据.
It is not possible
I looked around and found a german site tht explains, that the spec
of java-servlet define the WEB-INF folder as not client accessable,
cos it contains data as classes that never should be accessed from outside the server.
你最好使用 Executions.sendRedirect(java.lang.String uri)
通过单击按钮重定向需要服务器端操作.
如果您只想重定向,请设置按钮 href.
它应该看起来像
You should better use Executions.sendRedirect(java.lang.String uri)
to redirect by a button click with server-side action needed.
If you just want to redirect, set the buttons href.
It should look like
Executions.sendRedirect("/zul/home.zul");
或在 Java 中:
myButton.setHref("/zul/home.zul");
在祖尔:
<button ... href="/zul/home.zul" ...>
编辑
我可以写很多,但最好是说,如果你
Edit
I could write much, but the best would be to say, if you
- 不要使用 Spring 按照 这个,如果你得到 404
检查您的部署选项/部署的东西. - 使用 Spring,我更喜欢因为容易
ajax 登录站点,java 方法中的安全注释
和简单的 zk 集成,请遵循 zk 春季指南一>.
- do not use Spring follow this and if you get 404
check your deploy options/ deployed stuff. - use Spring, what I would prefer because of easy
ajax login site, security annotations at java methods
and easy zk integration, follow the zk guide for spring.
如果您仍然有 404 并且无法弄清楚,请发布您的
配置文件或类.
If you still have 404 and can't figure them out, please post your
configuration files or classes.
这篇关于zk框架:如何从zul目录下的WEB-INF加载zul页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!