私はjsp、jstl、jsfを使ってアプリケーションを開発しています。私の大学のプロジェクトでは、jsfにとって非常に新しいです。jsfからリダイレクトしますか?
これまでのところすべてがうまくいっています。しかし、私はdinamycパラメータを使ってマネージドBeanからページにリダイレクトする方法を考え出すのに問題があるようです。 例:article.jsp?article_id=2
誰かが私にそれがどのように行われたか教えていただけますか?
私は
FacesContext.getCurrentInstance().getExternalContext().dispatch("faces/article.jsp2?article_id=" + articleId);
ようsomethinngを使用しますが、エラーを取得しようとして:
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)
私は
response.sendRedirect("faces/article.jsp2?article_id=" + articleId);
return;
を使用しようとしているが、再びエラーを取得して。
javax.servlet.ServletException: Cannot forward after response has been committed
javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
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 = new ArrayList();
if(commentName.contains("<"))
{
error.add("Comment name contains illegal characters");
}
if(commentBody.isEmpty() && commentBody.contains("<script"))
{
error.add("Your message body contains illegal characters");
}
if(error.size() > 0)
{
request.getSession().setAttribute("error", error);
error.clear();
FacesContext.getCurrentInstance().getExternalContext().dispatch("article.jsp2?article_id=" + articleId);
}
else
{
Comment comment = new Comment();
comment.setCommentAuthor(authorName);
comment.setCommentBody(commentBody);
comment.setCommentDate(commentDate);
comment.setCommentName(commentName);
comment.setArticleId(articleId);
DisplayArticleIO addComment = new DisplayArticleIO();
addComment.postComment(comment);
// FacesContext.getCurrentInstance().getExternalContext().dispatch("faces/article.jsp2?article_id=" + articleId);
response.sendRedirect("faces/article.jsp2?article_id=" + articleId);
return;
}
ありがとうございます。
あなたは、いくつかの非常に素晴らしい提案を記載されている:私の問題を解決したものだ
。 ありがとう、確かにそれを調べます。 – Dmitris
あなたは大歓迎です:P – laginimaineb