home.jsp
<form method="POST" action="Initiater.do">
<table>
<tr>
<td>
Internal Diameter from FlowAss:
</td>
<td>
<input type="text" id="Id" />
</td>
<td>
Depth:
</td>
<td>
<input type="text" id="Depth" />
</td>
<td>
Units:
</td>
<td>
<select>
<option value="ft">feet</option>
<option value="mts">meters</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" />
</td>
</tr>
</table>
</form>
</body>
</html>
Home.java 公共(public)类 Home 扩展 HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
{
System.out.println("in Post");
String id = (String) request.getParameter("Id");
String depth = request.getParameter("Depth");
/*double id =Double.parseDouble(request.getParameter("Id"));
double depth =Double.parseDouble(request.getParameter("Depth"));*/
System.out.println("Id"+id);
System.out.println("Depth"+depth);
}
调用servlet Home.java的doPost方法,当我调试时,值id和深度返回空值,任何人都可以帮我解决这个问题。
最佳答案
将 name 属性添加到输入标记。
改变
<input type="text" id="Depth" />
<input type="text" id="Id" />
至
<input type="text" id="Depth" name="Depth"/>
<input type="text" id="Id" name="Id"/>
Request.getParameter
通过 name
属性而不是 id
获取数据
关于java - 基本 request.getParameter 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36436687/