• Post Reply Bookmark Topic Watch Topic
  • New Topic

Call a JSP

 
alan kent
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can I call a JSP from a servlet?
I have written the following code but it doesn`t work showing an error.
The following code is in servlet.
req.setAttribute("person", p1);
getServletContext().getRequestDispatcher("/result.jsp").forward(req,resp);
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but it doesn`t work showing an error.

Do you think it might be helpful to let us know what the error is?
bear
 
alan kent
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, in my case it did not work. I don`t know were is the mistake.
Do you know where can I find an example?.
I want to find an example of servlet calling a JSP.
 
Craig Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use the ServletContext interface to get a request dispatcher, the path used needs to be relative to the root of the ServletContext. So, in your app, is "/test.jsp" the correct path? How are you calling the servlet?
HTH
-Craig
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!