我的问题是如何隐藏网址中显示的zul扩展程序?
出于安全原因,我们不希望展示我们的应用程序中使用的技术。
网址:
http://localhost:8080/warname/index.zul
我希望网址看起来像这样:
http://localhost:8080/warname/index
或
http://localhost:8080/warname/
表示index.zul或.zul需要隐藏url。
ZK Version: 8.0.0
Server: wildfly-8.2.1.Final
jdk: jdk1.8.0_51
Eclipse Version: Neon.2 Release (4.6.2)
的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/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">
<display-name>test4</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>
答案 0 :(得分:1)
我只能按照 Bilbo Baggins 推荐:
更改网址格式
有很多方法可以做到这一点,这里只有几个......
如果URL中没有给出文件名,这将显示任何文件夹的index.zul。
使用HTTP服务器,例如将Apache httpd与mod_rewrite
如果要在应用程序服务器中保留内容,Servlet规范提供了一个方法RequestDispatcher.forward(),可以在servlet过滤器或servlet中使用
与此question/answer类似,您可以对zul文件执行相同操作。
package your.package;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
public class NoZulForwardingFilter implements Filter {
private static final String ZUL_VIEW_ROOT_PATH = "/pages";
private static final String ZUL_VIEW_SUFFIX = ".zul";
@Override
public void init(FilterConfig filterConfig) throws ServletException {}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpServletRequest = ((HttpServletRequest) request);
String servletPath = httpServletRequest.getServletPath();
//Only process the paths starting with /pages, so as other requests get unprocessed.
//You can register the filter itself for /pages/* only, too
if (servletPath.startsWith(ZUL_VIEW_ROOT_PATH)
&& !servletPath.contains(ZUL_VIEW_SUFFIX)) {
request.getRequestDispatcher(servletPath.concat(ZUL_VIEW_SUFFIX))
.forward(request, response);
} else {
chain.doFilter(httpServletRequest, response);
}
}
@Override
public void destroy() { }
}
并在您的web.xml中配置它
<filter>
<filter-name>nozulforwarding</filter-name>
<filter-class>your.package.NoZulForwardingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>nozulforwarding</filter-name>
<url-pattern>/pages/*</url-pattern>
</filter-mapping>
注意:这些技术中的任何一项都不会隐藏您的应用程序是用ZK编写的,因为它总是下载包含ZK客户端API的特定JavaScript文件。即使隐藏了部分网址,这也会让任何人明白你正在使用ZK。