Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

.htaccess with JSP  RSS feed

 
varun bihani
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, I have used .htaccess with my sites in php .. but does it also work with JSP.
becoz, JSP files will stay in tomcat/webapps directory and will run under port 8080..
I want to redirect in following way:
http:<mysite.com>:8080/<app>/<filename.jsp>?id=1 to http:<othersite.com>/filename.html

Can it be done?
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the sendRedirect(String) method on HttpServletResponse (the 'response' implicit object in a JSP) to redirect the client - this sends the HTTP "Temporary Redirect" header, and sets the "Location" (or equivalent) header to the URL passed as the argument to the method.

However, this method will throw an IllegalStateException if the response has been committed (which normally occurs when the response buffer is flushed for the first time). You therefore need to be extra diligant that nothing has been written to the client before invoking this method.

A better design would see this code inserted into a servlet rather than a JSP.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!