我在Google App Engine中出现重定向和Servlet问题。 我有一个index.jsp和一个list.jsp,但我无法得到预期的结果。
我在web.xml中有这个:
<filter-name>URIParserFilter</filter-name>
<filter-class>com.bbva.icaro2.web.filters.URIParserFilter</filter-class>
</filter>
<servlet>
<servlet-name>EntitiesAdminServlet</servlet-name>
<servlet-class>com.myproject.web.EntitiesAdminServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>ListServlet</servlet-name>
<servlet-class>com.myproject.web.ListServlet</servlet-class>
<jsp-files>/lists/lists.jsp</jsp-files>
</servlet>
<servlet-mapping>
<servlet-name>EntitiesAdminServlet</servlet-name>
<url-pattern>/admin/entities/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ListServlet</servlet-name>
<url-pattern>/lists/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
当我访问http://myproject/lists/mylist时 线程转到URIParserFilter:
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
String entityKind = null;
String id = null;
String pathInfo = ((HttpServletRequest)req).getPathInfo();
String pathString = (pathInfo == null || pathInfo.equals("/")) ? "" : pathInfo.substring(1);
String[] parts = pathString.split("/");
entityKind = parts[0].trim();
id = (parts.length > 1) ? parts[1].trim() : null;
req.setAttribute(Constants.REQ_ATTR_REQ_ENTITYKIND, entityKind); // entityKind = "mylist"
req.setAttribute(Constants.REQ_ATTR_REQ_ENTITYID, id);
chain.doFilter(req, resp);
}
然后它转到list.jsp whitout通过ListServlet :-( 如果http://myproject/admin/entities/hello它有效!
这些课程完全相同......
我做错了什么?
谢谢,抱歉我的英语不好......
答案 0 :(得分:1)
使用url pattern.it编写唯一的<jsp-files>
将重定向到jsp文件。
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.uks.MyServlet</servlet-class>
<jsp-files>/jsp/my.jsp</jsp-files>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
答案 1 :(得分:0)
从servlet转发到jsp页面。不要在web.xml中映射jsp。
所以你需要在你的servlet中做任何事情然后:
String destination = "/jsp/my.jsp";
RequestDispatcher rd = getServletContext().getRequestDispatcher(destination);
rd.forward(request, response);