Reputation: 1
I have problems whit redirections and Servlets in Google App Engine. I have an index.jsp and a list.jsp, but I can't get the results expected.
I have this in 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:
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!
The classes are exactly the same...
What I'm doing wrong?
Thanks, and sorry for my bad english...
Upvotes: 0
Views: 1553
Reputation: 3769
Do a forward from your servlet to your jsp page. Don't map the jsp in web.xml.
So do whatever you need to in your servlet and then:
String destination = "/jsp/my.jsp";
RequestDispatcher rd = getServletContext().getRequestDispatcher(destination);
rd.forward(request, response);
Upvotes: 0
Reputation: 383
write the only <jsp-files>
with url pattern.it will redirect to jsp file.
<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>
Upvotes: 1