下面是一个简单例子:
html部分:
<!DOCTYPE html>
<html>
<head>
<title>login.html</title>
<meta charset=UTF-8">
</head>
<body>
<form action="ch04.jsp" method="post">
用户名:<input type="text" name="username">只能输入字母或者数字,4-16个字符<br>
密码: <input type="password" name="pwd">密码长度6-12位<br>
确认密码:<input type="password" name="repwd"><br>
性别:<input type="radio" name="sex" value="男 ">男
<input type="radio" name="sex" value="女 ">女<br>
电子邮件:<input type="password" name="email">请输入正确的Email地址<br>
兴趣爱好:<input type="checkbox" name="like" value="PE">体育
<input type="checkbox" name="like" value="reading">读书
<input type="checkbox" name="like" value="music">音乐
<input type="checkbox" name="like" value="travl">旅游<br>
<input type="submit"><br>
<textarea name="协议" rows="15" cols="10"></textarea>
</form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'ch04.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<!-- 此处接收的是该文件夹中login.html的数据 -->
<%
//设置请求编码格式
request.setCharacterEncoding("UTF-8");
//getParameter获取请求传递的参数
//1、form表单传参
//2.页面url直接传参(get请求传参,?开始后边跟着参数列表,属性=属性值&属性=属性值的方式)
//3、密文形式传参(跟form表单的post请求方式一样)
String username=request.getParameter("username");
String pwd=request.getParameter("pwd");
//getParameterValues获取请求传递的参数(name相同的一组参数)
String [] likes=request.getParameterValues("like");
//4、获取ip地址
String ip=request.getLocalAddr();
%>
<body>
用户名是:<%=username %>
密码是:<%=pwd %> <br>
爱好:
<%
for(int i=0;i<likes.length;i++){
%>
<%=likes[i] %>
<%
}
%>
网址是: <%=ip %>
</body>
</html>