如何将参数从html页面发布到servlet

时间:2013-04-12 09:04:10

标签: java-ee

这是我的Dem.html页面无法正常执行当我点击“okeeee”按钮时没有事件被处理

<form action="http://localhost:7000//DemoS/MyServlet" method="post">
</form>
<input type="text" name="e">
<input type="text" name="p">
<input type="submit" value="Okeeeeeeee">

post servlet方法:

public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
  response.setContentType("text/html");
  PrintWriter out = response.getWriter();
  String e=request.getParameter("e");
  String p=request.getParameter("p");out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
  out.println("  <BODY>");
  out.println(", using the POST method abhinav   hiii"+e+""+p);
  out.println("  </BODY>");out.println("</HTML>");
}

1 个答案:

答案 0 :(得分:0)

您的输入必须包含在表单标记之间:

   <form action="http://localhost:7000//DemoS/MyServlet" method="post">
      <input type="text" name="e">
      <input type="text" name="p">
      <input type="submit" value="Okeeeeeeee">
   </form>