• Post Reply Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher IllegalStateException

 
Sudhanshu Mishra
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to understand the working of the forward and include method along with their behaviour with the response buffer.
I need help with the code below.


I require to fill in the details in the index.html page which has a single text field "name".If the name is 123 it is successful login.In case if the name is not 123,i need to display invalid attempt,but it should appear that "invalid attempt" is written on the index page itself(just like in standard login pages like that of gmail).I am getting IllegalStateException meaning the response buffer has already been committed.I want to know how?
Is there any other way achieve the objective of displaying the "invalid attempt" on index.jsp page itself in case of invalid login?

Thanks.....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not only is it poor practice to put Java code in a JSP, even if it weren't, why on earth would this code be in a JSP?
 
Sudhanshu Mishra
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply,but still i did not find my answer.Why am i getting the IllegalStateException ?I just want to know why it makes it a poor practice?

Thanks....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Putting Java in a JSP is a bad practice that has been discredited for over 10 years now and has been discussed many many times in these forums. Please SearchFirst.

Your exception is likely because the JSP is emitting needless output because this shouldn't be in a JSP in the first place. Please read this article to understand what JSP is and what it should be used for.

When you use a hammer instead of a saw to cut a board, you shouldn't be surprised when it doesn't get the job done correctly.
 
Sudhanshu Mishra
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear,
I just wanted to know that how is my JSP getting IllegalStateException,even if i am not using any outputstream except the implicit writer that JSP already has.And i am not even writing any thing from the writer before forwarding the request.

I am a beginner in JSP technology and hence am expecting a little explaination.Please help me out if possible.I have already referred articles on web and also on JavaRanch,but still unable to get why i am getting this exception.

Thanks....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already told you. It's likely the JSP is emitting output from the needless template text.

If you are a beginner in JSP you should be focusing on learning how to do things the proper way, and not wasting your time with Java code in JSPs.

Also, be sure to read this article.
 
Sudhanshu Mishra
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Bear.I am trying to learn to do the things right way,and hence seek guidance from you.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be sure to avoid Java code in JSPs, and to avoid using JSPs or anything other than creating the HRML view. It's very common for people to try and do things like what you have posted in a JSP, but that's a really poor practice. JSPs should be used for views only.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!