我在Google App Engine中遇到了白名單重定向和Servlet問題。 我有一個index.jsp和一個list.jsp,但我無法得到預期的結果。Google App Engine(Java) - 從web.xml重定向到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的情況下,它的工作原理!
這些類是完全一樣的...
我做錯了什麼?
謝謝,我的英語不好對不起......
IThanks的回答,它重定向到我的jsp「lists.jsp」但線程不經過我的servlet:ListServlet – tpdeoro 2012-03-14 12:04:27
那麼你想使用RequestDispatcher在servlet代碼內部重定向。 – 2012-03-14 12:06:39
但是...它從URIParserFilter.doFilter()直接到「lists.jsp」,我怎麼能強制它通過我的servlet重定向它? 我想我在我的web.xml中遇到了錯誤,但我不知道是什麼 – tpdeoro 2012-03-14 12:15:06