我在1.jsp页面把用户填写的单价,数量用session传到2.jsp页面,我想把1.jsp页面的数据传到2.jsp时显示的是单价*数量(或者说是总价)。新手,请详细说说谢了。。 

解决方案 »

  1.   

    还有,参数传递不要用sessioin,而是用表单提交到 2.jsp就行了。比如1.jsp
    <form method="post" action="2.jsp">
    价格:<input type="text" name="price"/>
    数量:<input type="text" name="qty"/>
    <input type="submit"/>
    </form>2.jsp  double price = 0;
      double qty = 0;
      try{
       price = Double.parseDouble(request.getParameter("price"));
      }catch(Exception ex){
        price = 0;
      }
      try{
       qty = Double.parseDouble(request.getParameter("qty"));
      }catch(Exception ex){
        qty= 0;
      }
      out.println(qty*price);
      

  2.   

      double price = 0;
      double qty = 0;
      try{
       price = Double.parseDouble(request.getParameter("price"));
      }catch(Exception ex){
        price = 0;
      }
      try{
       qty = Double.parseDouble((String)session.getAttribute("qty"));//通过session取得数量
      }catch(Exception ex){
        qty= 0;
      }
      out.println(qty*price);
      

  3.   

    1.jsp<%session.setAttribute("count",count);%>2.jsp<%=session.getAttribute("count");%>这样就能把1.jsp的东西在2.jsp中取到!
      

  4.   

    1.jsp页面代码type
    <input type="radio" name="type" value="10"/>
    <input type="radio" name="type" value="20"/>
    <input type="radio" name="type" value="30"/>
    price
          <input type="text" name="price" />
    category
          <select name="category">
            <option value="7.8">aaa</option>
            <option value="9.3">bbb</option>
          </select>
    到了2.jsp我想得到他们的总价应该怎样呢?总价是type*price*category