Servlet Application Data transfer between HTML pages

HI,
I have simple web application with few HTML files and corresponding servlets

Login.html is dependent to LoginServlet.java which leads to
Shop.html is dependent to OrderProcessServlet.java which leads to
billing.html is dependent to BillingServlet.java which leads to
ConfirmationServlet.java and finally leads to Banner.html
My question is how it is remembering data from one HTMl to other HTML. Is it is using request or session scope. I see both of them. What is default scope. What is the purpos of requestdeispatcher.formward here. Please advise.
shop.xml looks like


<html>
<head>
<title>Customer Form</title>
</head>
<body>
      <P align="center">
            <FONT size="6" color="#008040" face="Verdana"> Welcome to
                  BuyForLess </FONT>
      </P>
      <hr />
      <h4 align="center">
            <FONT size="3" face="verdana"> Please Select the following
                  items and click Buy to purchase </FONT>
      </h4>
      <form action="OrderProcessingServlet">
            <table border="1" cellspacing="1" cellpadding="1">
                  <tr>
                        <td align="center">Book Name</td>
                        <td align="center">Distributer</td>
                        <td align="center">Price</td>
                        <td align="center">Quantity</td>
                  </tr>
                  <tr>
                        <td align="center">Advanced J2EE</td>
                        <td align="center">Hall Publications</td>
                        <td align="center">$10.99</td>
                        <td align="center">Chapter 13 Request Dispatching Servlet
                              Programming 368 <SELECT name="j2eeQty">
                                    <OPTION value="0">0</OPTION>
                                    <OPTION value="1">1</OPTION>
                                    <OPTION value="2">2</OPTION>
                                    <OPTION value="3">3</OPTION>
                        </SELECT></td>
                  </tr>
                  <tr>
                        <td align="center">Perl Scripting</td>
                        <td align="center">Wrox Publications</td>
                        <td align="center">$9.99</td>
                        <td align="center"><SELECT name="perlQty">
                                    <OPTION value="0">0</OPTION>
                                    <OPTION value="1">1</OPTION>
                                    <OPTION value="2">2</OPTION>
                                    <OPTION value="3">3</OPTION>
                        </SELECT></td>
                  </tr>
                  <tr>
                        <td align="center">Red Roses</td>
                        <td align="center">CoolFlowers.com</td>
                        <td align="center">$1.99</td>
                        <td align="center"><SELECT name="flowerQty">
                                    <OPTION value="0">0</OPTION>
                                    <OPTION value="1">1</OPTION>
                                    <OPTION value="2">2</OPTION>
                                    <OPTION value="3">3</OPTION>
                        </SELECT></td>
                  </tr>
                  <tr>
                        <td></td>
                        <td align="center"><input type="submit" value="Checkout"
                              size="20" /></td>
                  </tr>
            </table>
      </form>
      <br />
      <i>Copyright 2001 BuyForLess.com</i>
</body>
</html>




billing.html looks like

<HTML>
<BODY>
<P align="center"><FONT size="6" color="#008040" face="Verdana">Welcome
to BuyForLess</FONT></P>
<P><BR>
</P>
<DIV align="center">
<hr />
<form action="BillingServlet">
<TABLE border="0">
<TBODY>
<TR>
<TD width="225">Card Type</TD>
<TD width="347"><INPUT type="radio" name="cardtype"
value="MasterCard" checked> MasterCard
<INPUT type="radio" name="cardtype" value="Visa">
VISA
</TD>
</TR>
<TR>
<TD width="225">Credit Card Number</TD>
<TD width="347">
<INPUT type="text" name="number" size="35"></TD>
</TR>
<TR>

<TD width="225">Expiration Date</TD>
<TD width="347"><INPUT name="date" size="15"></TD>
</TR>
<TR>
<TD width="225"></TD>
<TD width="347">
<INPUT type="submit" name="submit" value="Submit"></TD>
</TR>
</TBODY>
</TABLE>
</form>
</BODY>
<hr />

</HTML>



web.xml looks like


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">
  <servlet>
    <servlet-name>Hello</servlet-name>
    <servlet-class>HelloWorld</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Hello</servlet-name>
    <url-pattern>/HelloServlet</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>Hello1</servlet-name>
    <servlet-class>LoginServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Hello1</servlet-name>
    <url-pattern>/LoginServlet</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>Order</servlet-name>
    <servlet-class>OrderProcessingServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Order</servlet-name>
    <url-pattern>/OrderProcessingServlet</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>billing</servlet-name>
    <servlet-class>BillingServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>billing</servlet-name>
    <url-pattern>/BillingServlet</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>Confirmation</servlet-name>
    <servlet-class>ConfirmationServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Confirmation</servlet-name>
    <url-pattern>/ConfirmationServlet</url-pattern>
  </servlet-mapping>
    <servlet>
    <servlet-name>Banner</servlet-name>
    <servlet-class>BannerServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Banner</servlet-name>
    <url-pattern>/BannerServlet</url-pattern>
  </servlet-mapping>
</web-app>





Orderprocessing.java




import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
public class OrderProcessingServlet extends HttpServlet {
      protected void doGet(HttpServletRequest req, HttpServletResponse res)
      
      throws ServletException, IOException {
            // Read the form data.
            String j2eeQtyss = req.getParameter("j2eeQty");
            System.out.println("j2ee is"+j2eeQtyss);
            String perlQtyss = req.getParameter("perlQty");
            System.out.println("perlQty is"+perlQtyss);
            String flowersQtyss = req.getParameter("flowerQty");
            System.out.println("flowersQty is"+flowersQtyss);
      
            int q1 = Integer.parseInt(j2eeQtyss);
            int q2 = Integer.parseInt(perlQtyss);
            int q3 = Integer.parseInt(flowersQtyss);
            double totalPrice = q1 * 10.99 + q2 * 9.99 + q3 * 1.99;
            System.out.println("total price is"+totalPrice);

            HttpSession session = req.getSession(true);

            session.setAttribute("TotalPrice", new Double(totalPrice));
      
            req.getRequestDispatcher("/htmls/billing.html").forward(req, res);
      }
}



BillingServlet.java


import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
public class BillingServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
// Read the card details
String cardType = req.getParameter("cardType");
String number = req.getParameter("number");
String date = req.getParameter("date");
// Get the session
HttpSession session = req.getSession(true);
// Generate a confirmation number
long conf = (long) (Math.random() * 9999999);
// Store the data in the session
session.setAttribute("Confirmation", new Long(conf));
// Forward to Billing page
req.getRequestDispatcher("/ConfirmationServlet").forward(req, res);
}
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doGet(req, res);
}

}




Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
LVL 7
gudii9Asked:
Who is Participating?
 
ManishConnect With a Mentor LeadCommented:
When form is submitted, values will be in request scope,
in servlet, you are adding it in session scope, that will be available in session,
If you forward it, I think, request scope values also get added in it,
0
 
krishna kishore mellacheruvu venkataConnect With a Mentor Commented:
Please check this link. It may help you

http://docs.oracle.com/cd/E19644-01/817-5451/dwservlt.html
0
 
gudii9Author Commented:
when you forward session scope values will be added apart from request scope values. Please advise
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
gudii9Author Commented:
>>>When form is submitted, values will be in request scope


Also how form submitted values stored in request scope. Please advise
0
 
ManishLeadCommented:
--when you forward session scope values will be added apart from request scope values. Please advise
Yes

-Also how form submitted values stored in request scope
In JSP, there are forms, when you click on submit button,
then it will be in request scope,
Or when you hit direct URL, after question mark, there are values like a=b&b=c,
these are in request scope, etc,,,
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.