JSP - 转发已转发到另一个页面的属性

时间:2017-03-05 19:40:35

标签: jsp

第1页: 我转发以下内容:

<form action="purchase.jsp" method="GET">
          <input type = "hidden" name = "item_name" 
                 value = "${result.rows[0]['item_name']}" /> 
          <input type = "hidden" name = "item_code" 
                 value = "${result.rows[0]['item_code']}" />    
          <input type = "hidden" name = "item_price" 
                 value = "${result.rows[0]['item_price']}" /> 
          <input type = "submit" id="buy" value = "Buy" />
        </form>

然后在第二页收到它,当我请求attrbute时显示正常。

<%= request.getParameter( "item_name" ) %> (<%= request.getParameter( "item_code" ) %>) with a price of &pound;
<%= request.getParameter( "item_price" ) %> </h2>

现在这个参数出现在这个页面上,但是我想在另一个页面上使用这个参数,但首先我用表格发布它:

<form action="complete_purchase.jsp" method="POST">
  <input type="submit" value="Complete Purchase" />
  <input type = "hidden" name = "item_price" value = "${request.setAttribute(item_price)}" /> 
</form>

现在我想在最后一页上检索它,但它显示为NULL

You have bought: <%= request.getParameter( "item_name" ) %> (<%= request.getParameter( "item_code" ) %>) 
<br />
Total: &pound; <%= request.getParameter( "item_price") %> 

我做错了,它不会从第2页到第3页显示此参数?

1 个答案:

答案 0 :(得分:0)

问题在于第二种形式,您使用setAttribute代替getParameter

<form action="complete_purchase.jsp" method="POST">
  <input type="submit" value="Complete Purchase" />
  <input type = "hidden" name = "item_price" value = "<%= request.getParameter( "item_price" ) %>" /> 
</form>