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.
Both login.zul and home.zul are in zul directory along with their respective composers.
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);
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.
Thank in advance.
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>
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");
}
}
You cannot.
Files in /WEB-INF folder are not directly accessible. If you want to have such kind of file system then you should better integrate spring framework.
As others have noted direct/redirect access to pages under WEB-INF is not allowed by servlet specification, The best practice is to keep login.zul outside WEB-INF folder so users of application can have a direct access to it. Now for rest of the files you can keep them under WEB-INF folder and render them using include component or
Executions.createComponents()
.Generally I keep my partial zul pages in WEB-INF folder so they aren't directly accessible but I keep my layout pages eg. home.zul or main.zul outside WEB-INF folder (also they should be restricted to access if user isn't logged in) Refer here to learn how to restrict page access using Spring Security
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.
If you have the problems in a folder that is not WEB-INF:
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
or in java:
in zul:
Edit
I could write much, but the best would be to say, if you
check your deploy options/ deployed stuff.
ajax login site, security annotations at java methods
and easy zk integration, follow the zk guide for spring.
If you still have 404 and can't figure them out, please post your
configuration files or classes.
I hope this help some one:
Forward zul file to another zul file you can use this code
For Include zul pages on same zul page you can use this code