This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes how do i include servlet in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how do i include servlet in jsp" Watch "how do i include servlet in jsp" New topic
Author

how do i include servlet in jsp

roopa sudhi
Greenhorn

Joined: Oct 31, 2001
Posts: 16
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

Joined: Feb 13, 2002
Posts: 2
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

Joined: Nov 27, 2001
Posts: 7
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

Joined: Jun 04, 2001
Posts: 17
Use RequestDispatcher
rd = getServletContext().getRequestDispatcher("file to include - jsp or servlet");
rs.include();
roopa sudhi
Greenhorn

Joined: Oct 31, 2001
Posts: 16
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how do i include servlet in jsp