Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redirecting from Java Scriptlet in JSP

 
Jason Allen
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am in the process of writing an application that does various database actions. I currently have a Java class that handles all my database actions and a JSP page that will present the data. I'm trying to figure out how to redirect to a different URL based on what has happened on the previous screen. For instance, I have login screen, the login then calls a method of my database class to verify the user, it will return a boolean true/false to indicate whether permissions are valid. If the permissions are not valid, I want to redirect the user to an error page. If the permissions are valid, I want to continue on with the processing of the current jsp page. I currently am only using scriptlets of Java and have not intended to use Servlets. Is this possible within the <% %> context of the jps scriptlet? In ASP I would do a response.redirect "URL". I have seen mention of a response.sendRedirect("URL"), but when I try to use that, it doesn't recognize response.
Any ideas?
 
Paul Wetzel
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used the reponse.senRedirect() and it has worked so I don't know what you are doing wrong (maybe you could ellaborate with code and error mesg?) One thing to keep in mind is that if any of the response buffer has been committed, you get an illegel StateException ( once the buffer hhas been filled and sent to the client, you can't user response.sendRedirect()). You might try using: instead
hope this helps
paul
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason,
Please refer to this sample code which I verified. Generally we do not hard code the "http://localhost" part and "/MISApp" part. Just to check the concept , I hard coded.
 
Jason Allen
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys. I'm not sure exactly what I was doing wrong.
It works fine now. The only thing that I know has changed is that I moved the function from a <%! %> declaration to just straight inline code in the <% scriptlet %>.
Thanks for you replies.
Jason.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic