Sto lavorando all'applicazione con jsp, jstl e jsf per il mio progetto universitario, questo è stato detto, anch'io sono molto nuovo per jsf.reindirizza da jsf?
Tutto sta andando benissimo finora. Tuttavia, sembra che abbia un problema a capire come eseguire il reindirizzamento dal bean gestito alla pagina con i parametri dinamyc. Ad esempio article.jsp?article_id=2
Qualcuno può dirmi come è fatto?
ho cercato di usare come somethinng
FacesContext.getCurrentInstance().getExternalContext().dispatch("faces/article.jsp2?article_id=" + articleId);
Ma ottenere errore:
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)
ho cercato di utilizzare
response.sendRedirect("faces/article.jsp2?article_id=" + articleId);
return;
Ma ancora una volta ottenere un errore.
javax.servlet.ServletException: Cannot forward after response has been committed
javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
Qualcuno può dirmi come faccio a reindirizzare dal bean Java gestita quando si lavora con JSF?
Bellow è il mio codice (forse qualcosa di sbagliato in questo e perché reindirizzare non funziona).
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;
}
Grazie in anticipo.
È elencato alcune molto belle suggerimenti. Grazie mille, ci penserò sicuramente. – Dmitris
prego: P – laginimaineb