[英]How to get input value from one jsp page to another jsp page?
I am trying to get a one-page input value to another page while clicking the order button. 我正在尝试在单击订单按钮时将单页输入值添加到另一页。
while I will take a number of item value and click the order button, it will carry the value the order page. 虽然我将获取一些项目值并单击订单按钮,它将携带订单页面的值。 The page code is here,
页面代码在这里,
<td><%=rs.getString("product_price")%></td>
<td> <input type="number" name="no_item" value="1" /></td>
<td class="text-center" width="250">
<a href='order.jsp?u=<%=rs.getString("id")%>' class="btn btn-success">Order</a>
<a href='edit.jsp?u=<%=rs.getString("id")%>' class="btn btn-warning">Edit</a>
<a href='delete.jsp?d=<%=rs.getString("id")%>' class="btn btn-danger">Delete</a>
</td>
The order page code is here, 订单页面代码在这里,
<%
statement = connection.createStatement();
String u=request.getParameter("u");
String item_num =request.getParameter("no_item");
int num=Integer.parseInt(u);
String Data = "select * from products_tbl where id='"+num+"'";
rs = statement.executeQuery(Data);
String product_price;
while (rs.next()) {
%>
<input type="hidden" name="id" value='<%=rs.getString("id")%>'/>
<div class="form-group">
<h4 style="float:left; padding-right:8px;">Product Name:</h4> <h4> <%=rs.getString("product_name")%> </h4>
</div>
<div class="form-group">
<%
product_price = rs.getString("product_price"); int num1 = Integer.parseInt(product_price); %>
</div>
<%= item_num %>
<%= num1 %>
<%
}
%>
Onclick of order button add the input value in url query string. 单击订单按钮在url查询字符串中添加输入值。 you have need to use java script in jsp page.
你需要在jsp页面中使用java脚本。
<script>
function order(page, id){
input_value = document.getElementById('no_item').value;
location.href= page+"?u="+id+"&no_item="+input_value;
}
</script>
Add the onclick function within order button. 在订单按钮中添加onclick功能。
<a onclick="order('order.jsp', '<%=rs.getString("id")%>')" class="btn btn-success">Order</a>
In order.jsp page you will get the input value. 在order.jsp页面中,您将获得输入值。
request.getParameter("no_item");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.