This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread 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 Android Security Essentials Live Lessons this week in the Android 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.
 
jQuery in Action, 2nd edition
 
subject: how do i include servlet in jsp
 
Similar Threads
page directive
ServletRequest Attributes
include directive -> Can include web component?
how to call a servlet from a jsp
JSP String value obtained from servlet out