相关疑难解决方法(0)

从jsf重定向?

我正在为我的大学项目使用jsp,jstl和jsf进行应用程序,据说,我对jsf也很新.

到目前为止,一切都很顺利.但是,我似乎有一个问题,想知道如何从托管bean重定向到dinamyc参数的页面.例如article.jsp?article_id=2

有人能告诉我它是如何完成的吗?

我一直想尝试使用像

FacesContext.getCurrentInstance().getExternalContext().dispatch("faces/article.jsp2?article_id=" + articleId);
Run Code Online (Sandbox Code Playgroud)

但得到错误:

javax.servlet.ServletException: #{postComment.postClick}: javax.faces.FacesException: javax.servlet.ServletException: javax.faces.component.UIViewRoot cannot be cast to com.sun.faces.application.StateManagerImpl$TreeNode
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
Run Code Online (Sandbox Code Playgroud)

我一直在努力使用

response.sendRedirect("faces/article.jsp2?article_id=" + articleId);
            return;
Run Code Online (Sandbox Code Playgroud)

但又一次出错了.

javax.servlet.ServletException: Cannot forward after response has been committed
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我在使用jsf时如何从托管java bean重定向?

贝娄是我的代码(可能是错误的,这就是为什么重定向不工作).

HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();

        String articleId = request.getSession().getAttribute("article_id").toString();
        //String articleId  = request.getParameter("article_id");
        String authorName = request.getSession().getAttribute("user_name").toString();

        java.util.Calendar calendar = java.util.Calendar.getInstance();
        String commentDate = String.valueOf(calendar.get(java.util.Calendar.DAY_OF_MONTH)) + ".";
        commentDate += String.valueOf(calendar.get(java.util.Calendar.MONTH)) + ".";
        commentDate += String.valueOf(calendar.get(java.util.Calendar.YEAR));

         ArrayList error …
Run Code Online (Sandbox Code Playgroud)

java jsf jsp jstl javabeans

10
推荐指数
2
解决办法
5万
查看次数

标签 统计

java ×1

javabeans ×1

jsf ×1

jsp ×1

jstl ×1