redirect from jsf?

后端 未结 4 1047
梦如初夏
梦如初夏 2020-12-10 15:05

I am working on application with jsp, jstl and jsf for my college project, thats being said, I am as well very new to jsf.

Everything is going great so far. However,

相关标签:
4条回答
  • 2020-12-10 15:11
    FacesContext.getCurrentInstance().getExternalContext().redirect("http://www.myUrl.com");
    

    René

    0 讨论(0)
  • 2020-12-10 15:16

    Basically, something is already sending output to the client before you make the call to response.sendRedirect(). Once something has been sent to the browser you can't redirect or forward them to a different place.

    In general, any scenarios that might result in a redirect or a forward should be handled as early as possible in the request context to insure the redirect happens before you send any data to the client. Are you doing something like calling this code via a tag in the view?

    0 讨论(0)
  • 2020-12-10 15:21

    Why are you using dispatch in one place and redirect in the other? This isn't the source of the problem - not returning after sending responses, however, is. Other then that, if you don't mind, I have a few friendly suggestions:

    • You can use DateFormat to return the comment date as you want it (it will be much cleaner).
    • If the errors ArrayList only contains Strings, use generics (ArrayList<String>).
    • What are you doing with the errors?
    • Your sanitation of the commentName is very dangerous. You should use whitelisting instead of blacklisting - define what you wish to accept in a comment and block everything else. Right now someone could insert an <img> tag with a src pointing to a cookie stealing page which would result in a session hijack.
    • After changing the dispatch to a redirect add a return below it (you should always do this. Not doing this could result in what you're seeing right now, which is that you've already sent a response somewhere else, but since you haven't returned you've reached a place where you're trying to send another).
    0 讨论(0)
  • 2020-12-10 15:36

    In case some one will run into same problem.

    That's what solved my problem:

    FacesContext.getCurrentInstance().getExternalContext().redirect("article.jsp?article_id=" + articleId);
    
    0 讨论(0)
提交回复
热议问题