Hello friends I have very small doubt. I am giving you the following code where it is possible for me to instantite one servlet from another one if this is possible why we require . The code is working fine(I am using Weblogic 6.1).
Login.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD>
<form method="post" action="http://localhost:7001/LoginServlet"> Enter your UserName:<INPUT TYPE="text" NAME="user"><br> Enter your Password :<INPUT TYPE="password" NAME="pass"><br> <INPUT TYPE="submit" value="Sign-Up"> </form>
Creating an Instance of an Servlet and invoking its methods may seem to be correct in a java perspective.
But look at an web application perspective, in which you never know, whether the request to the servlet is comming in get method or post method. Since these two methods have their own pros and cons, it will not be right to invode only one method for whatever kind of request.
Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside HereWEBlog
Hi, I think we can initiate another servlet inside a servlet. But we have to remember that some methods inside our servlet are callback methods. It is called by web container. Web container have responsible to manage every request from client and send that request into proper servlet (and its methods)..
Well, yeah... it will generate your expected output... but why would you want to set it up this way? It seems like bad practice for three reasons:
First, as far as I can tell, there is no reason for SessionServlet to be a servlet at all. It could just as easily be a plain old java object that you pass the request and response object to. You really aren't using any of the servletness functionality.
Second, you shouldn't be calling the doGet() method directly... It is the job of the container to look at the request header and determine which service method to call.
Lastly, just because you have access to the request and response object does not mean that the servlet was initialized correctly. Test the ServletContext and see if it holds a reference to the same context as the rest of the application. I would guess that it doesn't because the container never called the init() method.
“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook