我有HttpServlet。它将用户重定向到不同的jsp页面,取决于用户想要执行的操作。例如重定向到index.jsp。 不同的动作我一直在PicoContainer的这样重定向到自定义未找到jsp页面
<component-instance key="index">
<com.epam.collections.web.IndexAction/>
</component-instance>
当用户写在浏览器前面的网址 - 1)我得到的动作名称 - index
String name = getActionName(req);
2)获取从PicoContainer的行动
Action action = (Action) pico.getComponentInstance(name);
3)执行动作 - 返回表示jsp页面名称的字符串
String view = action.exec(req, resp);
其中exec方法是
public String exec(HttpServletRequest req, HttpServletResponse resp) {
return "index";
}
4)转发用户index.jsp page
getServletContext().getRequestDispatcher(
"/WEB-INFO/pages/" + view + ".jsp").forward(req, resp);
我要转发用户notfound.jsp
页面时,没有在PicoContainer的行动。例如,某些blabla.do
应返回notfound.jsp
页面。但是当我做这样的
if (action == null) {
getServletContext().getRequestDispatcher(
"/WEB-INF/jsp/notfound.jsp").forward(req, resp);
return;
}
因为getComponentInstance
回报null
时动作不xml文件中存在 - 我有错误500
此外,我想重定向到该页面时,我写某事没有.do
在所有。例如ddd.dd
,plain
等,但我有404错误。