调用requestdispatcher.forward(request.response)时的java.lang.IllegalStateException;

时间:2012-08-19 09:11:37

标签: java servlets

try {

    PaperDAOImpl objPaperDAOImpl = new PaperDAOImpl();
    AuthorDAOImpl objAuthorDAOImpl = new AuthorDAOImpl();
    List<papersBean> listPaperBean = new ArrayList<papersBean>();
    List<List<Author>> listOfListAuthor = new ArrayList<List<Author>>();

    String title = null;
    String author = null;

    if (request.getParameter("searchtitle") != null) {
        title = request.getParameter("title").trim();
        if (title.trim().equals("")) {
            String error = " You must choice option search";
            request.setAttribute("error", error);

        } else {
            listPaperBean = objPaperDAOImpl.SearchPaperByTitle(title
                    .trim());
            request.setAttribute("listresult", listPaperBean);
            // Get List Author Name , List

            if (!listPaperBean.isEmpty()) {

                for (int i = 0; i < listPaperBean.size(); i++) {
                    List<Author> listAuthor = objAuthorDAOImpl
                            .GetListAuthorByIdPaper(listPaperBean
                                    .get(i).getIdPaper());
                    if (listAuthor != null) {
                        listOfListAuthor.add(listAuthor);
                    }
                }
                int size = 0; // for debug
                size = listOfListAuthor.size(); // for debug

                request.setAttribute("lolAuthor", listOfListAuthor);
                RequestDispatcher rd = request
                        .getRequestDispatcher("front-end/search.jsp");
                rd.forward(request, response);
                return;

            }
        }
    }

} catch (ServletException e) {
    e.printStackTrace();
}

finally {

}

这是MyServlet for Search数据。

当我调试到util行时:

 `RequestDispatcher rd = request.getRequestDispatcher("front-end/search.jsp");`  

一切都好。并且"listOfListAuthor" , "listPaperBean"有数据......但是当调试到行时:

rd.forward(); ---&gt;我有一个问题,我仍然无法解决。

**Aug 19, 2012 3:48:52 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException
at managerpapers.system.servletController.FESearchTitle.processRequest(FESearchTitle.java:73)--This is rows : `rd.forward()`;**

这是MyServlet for Search数据!我为此整天调试。这是我的论文。一个不了解servlet master。有谁有想法吗 ?

这是MyServlet for Search数据!我为此整天调试。这是我的论文。一个不了解servlet master。有没有人有任何想法?

1 个答案:

答案 0 :(得分:0)

Javadoc中所述,servletContext的requestDispatcher必须以“/”开头,并被解释为相对于当前上下文根。
所以而不是:
 RequestDispatcher rd = request.getRequestDispatcher("front-end/search.jsp");

试试这个:
RequestDispatcher rd = request.getRequestDispatcher("/front-end/search.jsp");

我希望它会帮助你