J
Jeff Kish
Hi.
I'm looking at the lessons in:
http://pdf.moreservlets.com/More-Servlets-and-JSP-Chapter-02.pdf
The servlet java class is at the bottom.
There is some html that I can target in my browser that uses the
servlet... the html looks like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Collecting Three Parameters</TITLE>
</HEAD>
<BODY BGCOLOR="#FDF5E6">
<H1 ALIGN="CENTER">Collecting Three Parameters</H1>
<FORM ACTION="/servlet/moreservlets.ThreeParams">
First Parameter: <INPUT TYPE="TEXT" NAME="param1"><BR>
Second Parameter: <INPUT TYPE="TEXT" NAME="param2"><BR>
Third Parameter: <INPUT TYPE="TEXT" NAME="param3"><BR>
<CENTER><INPUT TYPE="SUBMIT"></CENTER>
</FORM>
</BODY>
</HTML>
my question is.. what exactly is going on internally?
Specifically, I enter in my browser:
http://ThreeParamsForm.html
and I get first a form that allows the user to enter 3 values.
Then when you click on the
submit query button the second form comes up showing the three params
and their values.
It appears to me that when I enter the ThreeParamsForm.html in the
browser, Tomcat says, ok..load the page ThreeParamsForm.html and send
it to the browser.
I assume it is the browser which process the html page, and I guess it
reads all the html, and associates the clicking of the button or
hitting of the return key with invoking the servlet (that is what
input_type="submit" gets you, right?)
Then the act of hitting enter or clicking on the submit button causes
the Tomcat to put the param1,param2,param3 values in session level
data (I guess?) and does a 'get', causing the doget method to be
invoked, which has access to the (session?) level param1,2,3
variables.
Is this correct, or am I missing something?.
Are these session level variables, or something else?
If they are session level, then if there was another submit button
with yet another servlet, would that servlet have access to the same
data?
thanks
bottom
package moreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Simple servlet that reads three parameters from the
* form data.
*/
public class ThreeParams extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Reading Three Request Parameters";
out.println(ServletUtilities.headWithTitle(title) +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=\"CENTER\">" + title + "</H1>\n" +
"<UL>\n" +
" <LI><B>param1</B>: "
+ request.getParameter("param1") + "\n" +
" <LI><B>param2</B>: "
+ request.getParameter("param2") + "\n" +
" <LI><B>param3</B>: "
+ request.getParameter("param3") + "\n" +
"</UL>\n" +
"</BODY></HTML>");
}
}
I'm looking at the lessons in:
http://pdf.moreservlets.com/More-Servlets-and-JSP-Chapter-02.pdf
The servlet java class is at the bottom.
There is some html that I can target in my browser that uses the
servlet... the html looks like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Collecting Three Parameters</TITLE>
</HEAD>
<BODY BGCOLOR="#FDF5E6">
<H1 ALIGN="CENTER">Collecting Three Parameters</H1>
<FORM ACTION="/servlet/moreservlets.ThreeParams">
First Parameter: <INPUT TYPE="TEXT" NAME="param1"><BR>
Second Parameter: <INPUT TYPE="TEXT" NAME="param2"><BR>
Third Parameter: <INPUT TYPE="TEXT" NAME="param3"><BR>
<CENTER><INPUT TYPE="SUBMIT"></CENTER>
</FORM>
</BODY>
</HTML>
my question is.. what exactly is going on internally?
Specifically, I enter in my browser:
http://ThreeParamsForm.html
and I get first a form that allows the user to enter 3 values.
Then when you click on the
submit query button the second form comes up showing the three params
and their values.
It appears to me that when I enter the ThreeParamsForm.html in the
browser, Tomcat says, ok..load the page ThreeParamsForm.html and send
it to the browser.
I assume it is the browser which process the html page, and I guess it
reads all the html, and associates the clicking of the button or
hitting of the return key with invoking the servlet (that is what
input_type="submit" gets you, right?)
Then the act of hitting enter or clicking on the submit button causes
the Tomcat to put the param1,param2,param3 values in session level
data (I guess?) and does a 'get', causing the doget method to be
invoked, which has access to the (session?) level param1,2,3
variables.
Is this correct, or am I missing something?.
Are these session level variables, or something else?
If they are session level, then if there was another submit button
with yet another servlet, would that servlet have access to the same
data?
thanks
bottom
package moreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Simple servlet that reads three parameters from the
* form data.
*/
public class ThreeParams extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Reading Three Request Parameters";
out.println(ServletUtilities.headWithTitle(title) +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=\"CENTER\">" + title + "</H1>\n" +
"<UL>\n" +
" <LI><B>param1</B>: "
+ request.getParameter("param1") + "\n" +
" <LI><B>param2</B>: "
+ request.getParameter("param2") + "\n" +
" <LI><B>param3</B>: "
+ request.getParameter("param3") + "\n" +
"</UL>\n" +
"</BODY></HTML>");
}
}