Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 重定向到自定义未找到的jsp页面_Java_Servlets_Picocontainer - Fatal编程技术网

Java 重定向到自定义未找到的jsp页面

Java 重定向到自定义未找到的jsp页面,java,servlets,picocontainer,Java,Servlets,Picocontainer,我有一个HttpServlet。它将用户重定向到不同的jsp页面,具体取决于用户想要执行的操作。 例如http://localhost:8080/collections/index.do重定向到index.jsp。 我在picocontainer中保留的不同动作如下 <component-instance key="index"> <com.epam.collections.web.IndexAction/> </component-instance>

我有一个HttpServlet。它将用户重定向到不同的jsp页面,具体取决于用户想要执行的操作。 例如
http://localhost:8080/collections/index.do
重定向到index.jsp。 我在picocontainer中保留的不同动作如下

<component-instance key="index">
    <com.epam.collections.web.IndexAction/>
</component-instance>
if (action == null) {
        getServletContext().getRequestDispatcher(
                "/WEB-INF/jsp/notfound.jsp").forward(req, resp);
        return;
    }
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页面

getServletContext().getRequestDispatcher(
            "/WEB-INFO/pages/" + view + ".jsp").forward(req, resp);
当picocontainer中没有操作时,我想将用户转发到页面
notfound.jsp
。例如,一些
blabla.do
应该返回
notfound.jsp
页面。但是当我喜欢这个的时候

<component-instance key="index">
    <com.epam.collections.web.IndexAction/>
</component-instance>
if (action == null) {
        getServletContext().getRequestDispatcher(
                "/WEB-INF/jsp/notfound.jsp").forward(req, resp);
        return;
    }
因为当xml文件中不存在操作时,
getComponentInstance
返回
null
,所以出现错误500

另外,当我在没有
的情况下写东西时,我想重定向到这个页面。例如
ddd.dd
plain
等等,但我有404错误。

1)要处理404错误,需要在web.xml中设置404处理程序 2) 您犯了500个错误,因为您的jsp页面可能有问题,您需要仔细检查jsp代码 3) 使用pico的方式是一种反模式,请查看pico文档