File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how do i include servlet in jsp

 
roopa sudhi
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
I need to include a servlet[a basic authentication servlet which will assign a session for the authenticated user]
in my JSP page to check whether the person accessing that page is authenticated.
I tried to use include but i am getting error saying the servlet was not found im sure the path is correct.
I tried to use <jsp:include page="" flush="true">
this doesnt throw any error but it is not authenticating the person.
I appreciate any help.
Thanks,
Roopa
 
Manikandan Pattathil
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually the scenario explained will be handled like this. You dont have to include a JSP in Servlet.
1. Validate the login and authenticate the user.
2. If logged in forward to Success.jsp
3. Else forward to Failure.jsp
You can use the sendRedirect() method in HTTPServletResponse class to navigate to the Success.jsp or Failure.jsp depending on the condition.
See below from API method help.
---------------------------------------------
sendRedirect
public abstract void sendRedirect(String location) throws IOException
Sends a temporary redirect response to the client using the specified redirect location URL. The URL must be absolute (for example, https://hostname/path/file.html). Relative URLs are not permitted here.
Parameters:
location - the redirect location URL
Throws: IOException
If an I/O error has occurred.
---------------------------------------------
 
john wu
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not include a servlet, but you can use a servlet in your jsp.
there are three options for using a servlet in jsp.
1. import your servlet class, and create a instance of servlet in your jsp.
2. make your servlet as a bean of your jsp.
3. write your own tag library.
hope these three cents are helpful.
 
tatae alvostru
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use RequestDispatcher
rd = getServletContext().getRequestDispatcher("file to include - jsp or servlet");
rs.include();
 
roopa sudhi
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for ur replies,
I used forward,and a jsp to store the original url from where it went.so that it can come back to the same page.
thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic