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

Efficient way to link two jsps  RSS feed

 
Ria Dev
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which one is good practice while linking 2 jsps.
1) Link jsps by : onClick="window.location=a.jsp';"
2) Link jsps by : submit the jsp form to a servlet
In servlet, use request.getRequestDispatcher("a.jsp").forward(request, response);

On what circumstances, do i need to select one over another?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(1) is a poor practice as you should never be linking directly to a JSP, but to its page controller.
 
Ria Dev
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, you should always use server-relative URLs beginning with the context path.

Also, it's not a bad practice to use JavaScript to link two pages when that's appropriate -- the bad practice is directly linking to a JSP rather than its controller.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!