• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

.htaccess with JSP  RSS feed

 
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?
 
Author
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!