2.jsp
<%@ 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 '2.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>
<body>
<h2>接收从index.jsp发送过来的数据</h2>
<!--
GET方法提交时,中文乱码的解决方案有2种:
1).对获取的参数数据进行转换,转换为byte数组,再把byte数组重新编码为UTF-8格式的字符串
2).修改tomcat服务器目录下的conf目录里的server.xml文件,在Connector节点那里添加
属性 URIEncoding="UTF-8",重启服务器就可以了
-->
<%
String sitename=request.getParameter("sitename");
/* byte[] bt= sitename.getBytes("ISO8859-1");
sitename=new String(bt,"UTF-8");
*/
%>
网站名: <%=sitename %><br>
网址:<%=request.getParameter("url") %>
</body>
</html>
3.jsp
<%@ 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 '2.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>
<body>
<h2>接收从index.jsp发送过来的数据</h2>
<!--
POST方法提交时,中文乱码的解决方案:
在第1句获取表单参数的前面加上request.setCharacterEncoding("UTF-8")
-->
<%
request.setCharacterEncoding("UTF-8");
String sitename=request.getParameter("sitename");
String url=request.getParameter("url");
String[] citys= request.getParameterValues("city");
for(String s:citys){
%>
城市:<%=s %><br>
<%
}
%>
网站名: <%=sitename %><br>
网址:<%=url %>
</body>
</html>
index.jsp
<%@ 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 'index.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>
<body>
<h2>网站表单--GET方法提交</h2>
<form action="2.jsp">
网站名:<input type="text" name="sitename"><br>
网址:<input type="text" name="url"><br>
<input type="submit" value="GET提交">
</form>
<h2>网站表单--POST方法提交</h2>
<form action="3.jsp" method="post">
网站名:<input type="text" name="sitename"><br>
网址:<input type="text" name="url"><br>
校区城市:<input type="checkbox" name="city" value="beijing">北京
<input type="checkbox" name="city" value="shanghai">上海
<input type="checkbox" name="city" value="wuhan">武汉
<input type="submit" value="POST提交">
</form>
</body>
</html>