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

Do not hard code jsp links inside servlet  RSS feed

 
Ali Gordon
Ranch Hand
Posts: 182
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning JSP and Servlets. Consider the following code inside the doPost method of a Servlet which forwards a HTTP request to a JSP -



I wonder what will happen if someone wants this servlet to forward the request to another jsp instead of the one above ? Does one have to go
and change this code manually every time in their application ? How can one free oneself of all this manual work ?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's why just about any web framework has introduced an abstraction around this, so that you can use a logical name for a JSP instead of its file name. Sort of like servlets are mapped in web.xml from a logical name to a class name - that allows you to change the class without having to change any of the URLs it's mapped to.
 
Devaka Cooray
Marshal
Posts: 5322
575
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I happen not to use any external framework, I use a text/properties file to address that problem.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How often do you think that situation arises? (Hint: hardly ever.)
 
Ali Gordon
Ranch Hand
Posts: 182
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:How often do you think that situation arises? (Hint: hardly ever.)

Thanks. I was wondering if Spring and such frameworks also handle mappings mentioned in my question.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!