• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Redirecting from Java Scriptlet in JSP

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic