jsp页面
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="get">
姓名
<label>
<input type="text" name="username" />
</label>
<p>密码
<label>
<input name="password" type="password" id="password" />
</label>
</p>
<p>性别
<label>
<input type="radio" name="usersex" value="男" />
</label>
男
<label>
<input type="radio" name="usersex" value="女" />
</label>
女</p>
<p>出生年月
<label>
<select name="select">
<option value="1990">1990</option>
<option value="1991">1991</option>
<option value="1992">1992</option>
<option value="1993">1993</option>
<option value="1994">1994</option>
</select>
</label>
年
<label>
<select name="select2">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
</label>
月
<label>
<select name="select3">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
</label>
日</p>
<p>个人爱好
<label>
<input type="checkbox" name="aihao" value="游戏" />
</label>
游戏
<label>
<input type="checkbox" name="aihao" value=" 游泳" />
</label>
游泳
<label>
<input type="checkbox" name="aihao" value="看书" />
</label>
看书</p>
<p>
<label>个人性格 </label>
<label>
<select name="xingge" size="4" multiple="multiple" id="xingge">
<option value="温柔">温柔</option>
<option value="野蛮">野蛮</option>
<option value="可爱">可爱</option>
</select>
</label>
</p>
<p>
<label>
备注
<textarea name="beizhu" id="beizhu"></textarea>
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
<label>
<input type="reset" name="Submit2" value="重置" />
</label>
</p>
</form>
</body>
</html>
当进行了action后转至get,这个sevlet进行接受参数处理
get.java
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 get extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
String username=request.getParameter("username");
String password=request.getParameter("password");
String usersex=request.getParameter("usersex");
String year=request.getParameter("year");
String month=request.getParameter("month");
String day=request.getParameter("day");
String[] aihao=request.getParameterValues("aihao");
String[]xingge=request.getParameterValues("xingge");
String beizhu=request.getParameter("beizhu");
//输出就只对多选的部分写出代码,其他直接out.print(username);等即可
out.println("爱好");
for(int i=0;i<aihao.length;i++){
out.println(aihao[i]);
}
out.println("性格");
for(int i=0;i<xingge.length;i++){
out.println(xingge[i]);
}
}
}