Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet call from index.jsp

 
Yayathi Jayaraman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I called a servlet from index.jsp its successfully loaded, after creating a database and stored a value into bean need to redirect the same page to display the bean in index.jsp.
Can anyone tell me what to write in servlet init() method to redirect into index.jsp page

Thanks in advance.









 
G krishna kumar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use requestDispatcher to redirect to the same page i.e index.jsp in your servlet service()...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yayathi Jayaraman wrote:Can anyone tell me what to write in servlet init() method to redirect into index.jsp page

The init() method has nothing at all to do with servicing a request. This is not the place to do anything like that.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jagdeesh kumar wrote:use requestDispatcher to redirect to the same page i.e index.jsp in your servlet service()...

Nope. The RequestDispatcher is used to forward to a JSP. A redirect is accomplished via the sendRedirect() method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic