"); Chapter 8 © copyright Janson Industries 2011"> "); Chapter 8 © copyright Janson Industries 2011">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

In Class Assg 3 - Solution

Similar presentations


Presentation on theme: "In Class Assg 3 - Solution"— Presentation transcript:

1 In Class Assg 3 - Solution
Sale.html should invoke SaleServlet Create SaleServlet to: Echo back the data from the Sale Web Page Sale Servlet User Sale.html HTML (response) With Sale info Chapter 8 © copyright Janson Industries 2011

2 © copyright Janson Industries 2011
import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class SaleServlet extends HttpServlet { private static final long serialVersionUID = 1L; public SaleServlet() { super(); } protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); try { PrintWriter out = new PrintWriter(resp.getOutputStream()); String CustName = req.getParameter("CustName"); String ItemName = req.getParameter("ItemName"); String Qty = req.getParameter("Qty"); String Price = req.getParameter("Price"); out.println("<HTML>"); Chapter 8 © copyright Janson Industries 2011

3 In Class Assg 3 - Solution
out.println("<HEAD><Title>Servlet Response</Title></HEAD>"); out.println("<BODY>"); out.println("The customer name is: " + CustName + "<BR>"); out.println("The item name is: " + ItemName + "<BR>"); out.println("The quantity is: " + Qty + "<BR>"); out.println("The price is: " + Price + "<BR>"); out.println("</BODY>"); out.println("</HTML>"); out.close(); } catch (Exception e) { System.out.println("Sample Servlet failed: "); e.printStackTrace(); } Don’t forget to change Sale.html to invoke SaleServlet Chapter 8 © copyright Janson Industries 2011


Download ppt "In Class Assg 3 - Solution"

Similar presentations


Ads by Google