form表单 与Servlet之间的参数传送
来源:互联网 发布:广州大数据局 编辑:程序博客网 时间:2024/06/07 05:18
<input name="name" />
<input name="pass" />
<input type="submit" value="mySubmit"/>
</form>
然后TestServlet这个Servlet的doget / dopost 来处理参数 name 和pass
servlet 中用request.getParameter("参数名称");
就可以得到参数
package com.lihuixing.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public TestServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// String dddd = request.getParameter("id");
// System.out.println(dddd);
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.println("测试");
// out.println(dddd);
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String nameString= request.getParameter("name");
String passString = request.getParameter("pass");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.println("测试");
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
- form表单与Servlet之间的参数传送
- form表单 与Servlet之间的参数传送
- JSP Servlet之 form表单 与Servlet之间的参数传送
- JSP 表单与Servlet之间的参数传送 .
- 如何在servlet中获取jsp中form表单提交的变量,以及jsp与servlet之间的数据传递
- Form表单传递参数到Servlet的原理
- jsp与servlet之间的参数传递
- jsp与servlet之间的参数传递
- jsp与servlet之间的参数传递
- servlet如何处理html form表单上传文件的同时传入的参数
- Servlet第三课 Form 表单的应用
- servlet实现form表单的文件上传
- Servlet获取form表单上传文件及其他参数
- Servlet处理Form表单
- jquery 与 webservice 之间json的传送
- Form表单提交参数类型与后台实体参数类型的问题
- form表单传参数,后台代码接收到的参数与预期不符
- Form与Form之间的通信
- opencv实现最基本的图像配准
- Android 学习记录之requestWindowFeature属性解析
- android仿12306图片验证码选择——自定义控件
- Android 用Canvas 画几何图形,画出小黄人
- Caused by: java.lang.ClassNotFoundException: net.sf.json.JSONObject
- form表单 与Servlet之间的参数传送
- 安卓获取安全码SHA1
- event.cancelBubble
- leetcode 312. Burst Balloons 分析
- iOS - 固定宽度和字号,获取Label的frame;固定高度和字号,获取Label的frame
- jQuery Mobile加载外部文件的问题
- TexView中的ellipsize属性
- php apc缓存
- vim命令图解