2013-06-26 72 views
0

我有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.ddplain等,但我有404错误。

回答

0

1)来处理你需要设置404处理器在web.xml 2)你有500 ERR 404错误,原因可能是什么是错的关于你的JSP页面,您需要检查JSP代码仔细 3)的方式您使用pico是反模式,请检查pico文档

相关问题