2012-03-14 56 views
0

我在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的情況下,它的工作原理!

這些類是完全一樣的...

我做錯了什麼?

謝謝,我的英語不好對不起......

回答

1

寫的唯一<jsp-files>與URL pattern.it會重定向到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> 
+0

IThanks的回答,它重定向到我的jsp「lists.jsp」但線程不經過我的servlet:ListServlet – tpdeoro 2012-03-14 12:04:27

+0

那麼你想使用RequestDispatcher在servlet代碼內部重定向。 – 2012-03-14 12:06:39

+0

但是...它從URIParserFilter.doFilter()直接到「lists.jsp」,我怎麼能強制它通過我的servlet重定向它? 我想我在我的web.xml中遇到了錯誤,但我不知道是什麼 – tpdeoro 2012-03-14 12:15:06

0

從您的servlet轉發到您的jsp頁面。不要在web.xml中映射jsp。

所以,做任何你需要在你的servlet,然後:

String destination = "/jsp/my.jsp"; 
RequestDispatcher rd = getServletContext().getRequestDispatcher(destination); 
rd.forward(request, response);