简体   繁体   English

Google App Engine(Java)-从web.xml重定向到jsp

[英]Google App Engine (Java) - Redirection to jsp from web.xml

I have problems whit redirections and Servlets in Google App Engine. 我在Google App Engine中进行重定向和Servlet时遇到问题。 I have an index.jsp and a list.jsp, but I can't get the results expected. 我有一个index.jsp和list.jsp,但是无法获得预期的结果。

I have this in web.xml: 我在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>

When I access to http://myproject/lists/mylist The thread goes to URIParserFilter: 当我访问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);
}

And then it goes to list.jsp whitout pass through ListServlet :-( In case of http://myproject/admin/entities/hello it works! 然后通过ListServlet传递到list.jsp,如果没有http:// myproject / admin / entities / hello,它将起作用!

The classes are exactly the same... 这些类完全相同...

What I'm doing wrong? 我做错了什么?

Thanks, and sorry for my bad english... 谢谢,抱歉我的英语不好。

write the only <jsp-files> with url pattern.it will redirect to jsp file. 用URL模式编写唯一的<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>  

Do a forward from your servlet to your jsp page. 从servlet到jsp页面进行转发。 Don't map the jsp in web.xml. 不要在web.xml中映射jsp。

So do whatever you need to in your servlet and then: 因此,您需要在servlet中执行任何操作,然后:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM