如何使用不属于任何形式的字段的形式将参数从jsp传递给servlet而不使用session.i认为代码可能看起来像下面的示例,但不适用于me.plz帮助我.
在index.jsp中: -
<form method="Post" action="servlet">
<input type="text" name="username">
<input type="password" name="password">
<%
int z=1;
request.setAttribute("product_no", z);%>
<input type='submit' />
</form>
Run Code Online (Sandbox Code Playgroud)
在servlet.java:-
int x=Integer.parseInt(request.getAttribute("product_no").toString());
Run Code Online (Sandbox Code Playgroud)
您的表单需要提交,例如有一个提交按钮.您需要将参数作为输入.request.setAttribute在表单内调用不会做任何事情.设置请求属性是为了在您打算使用调度程序转发请求时,而不是在使用表单时.
<% int z=1; %>
<form method="Post" action="servlet">
<input type="text" name="username" />
<input type="password" name="password" />
<input type="hidden" name="product_no" value="<%=z%>" />
<input type='submit' />
</form>
Run Code Online (Sandbox Code Playgroud)
您可以使用以下方法接收表单中提交的参数:
用request.getParameter( "字段名");
对于intance,您的servlet可以获取所有字段:
request.getParameter("fieldname");
Run Code Online (Sandbox Code Playgroud)
您还可以从链接发送参数,例如: __CODE__
| 归档时间: |
|
| 查看次数: |
45146 次 |
| 最近记录: |