Search This Blog

Friday, 14 September 2012

Practical 21) Create a Java class called Product with the following roperties: name, description, price. Create a listener that notifies (through System.out) whenever a user adds a product to a shopping cart (i.e. adds an object to the session object) or removes it again. Hint: check out the class HttpSessionAttributeListener. Make it print the name and price of the object (hint: access the session through the HttpBindingEvent object). Also, let the listener print the total price of all objects saved in the session so far (one way to accomplish this could be to keep a collection of all objects saved to the session – or just their keys – in the listener or an associated class).


Filename-addproduct.jsp

<html>
addattribute
<% session.setAttribute("iPhone","10000"); %>
<% session.setAttribute("iPoid","1"); %>
<% session.setAttribute("iPade","2"); %>

<% out.println(session.getValue("iPhone")); %>

</html>
Filename-input.jsp

<html>
<title>
          Input data.
</title>
<body>
          <form action="http://localhost:8090/wtad/def21/productbean.jsp">
                   Name:
                   <input type="text" name="name"/>
                   <br>
                   Description
                   <input type="text" name="des"/>
                   <br>
                   Price
                   <input type="text" name="price"/>
                   <br>
                   <input type="submit"/>
          </form>
</body>
</html>

Filename-onlinebean.jsp

<html>
<title>
          Onlineshoping Bean.
</title>
<body>
          <jsp:useBean id="p1" class="def21.Onlineshoping" />
         
          <jsp:setProperty name="p1" property="name" param="get"  />
          <%
                   String sget=request.getParameter("get");
                   session.setAttribute(sget,"1000");
          %>
         
          Shoping Data:
          ${p1.name}
         
</body>
</html>

Filename-onlineshoping.jsp

<html>
<title>
          Online Shoping
</title>
<body>
<form action="http://localhost:8090/wtad/def21/onlinebean.jsp">
          <table border="1" align="center">
                   <tr>
                   <td>Apple-iphone<input type="radio" name="get"  value="Apple-iphone"/></td>
                   </tr>
                   <tr>
                   <td>Apple-ipod<input type="radio" value="Apple-ipod" name="get"/></td>
                   </tr>
                   <tr>
                   <td>Apple-Notepad<input type="radio" value="Apple-Notepad" name="get"/></td>
                   </tr>
                   <tr>
                             <td rowspan="2"> <input type="submit" /></td>
                   </tr>
          </table>
</form>
</body>
</html>

Filename-productbean.jsp
<html>
<title>
          Process bean.
</title>
<body>

          <jsp:useBean id="p1" class="def21.Product" />
          <jsp:setProperty name="p1" property="*"  />
          <%--<jsp:getProperty name="p1" property="name" />--%>
          Name: ${p1.name}
          <br>
          <%-- <jsp:setProperty name="p1" property="des"  />
           <jsp:getProperty name="p1" property="des" /> --%>
          Description: ${p1.des}
          <br>
          <%-- <jsp:setProperty name="p1" property="price"  />
           <jsp:getProperty name="p1" property="price" /> --%>
          Price: ${p1.price}
         
</body>
</html>

Filename-removeattribute.jsp
<html>
Remove attribute
<%
          session.removeAttribute("p1");
%>

</html>

No comments:

Post a Comment