关于表单的h5界面
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%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 'form.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">
-->
<style type="text/css">
div{
background-color: yellow;
text-align: center;
}
h2{
text-align: center;
}
.zh{
color: pink;
}
.sb{
color: red;
font-weight: 700;
}
.tj{
color: green;
font-weight: 700;
}
</style>
</head>
<body>
<div>
<h1>欢迎登录本系统</h1>
<form action="result.jsp" method="post">
请您输入账号:<input type="text" name="account" value="请您输入账号" class="zh"><br><br>
请您输入密码:<input type="password" name="password"><br><br>
请您选择性别: <input type="radio" name="sex" value="男" checked="">男
<input type="radio" name="sex" value="女" >女 <br><br>
请选择您的爱好:<input type="checkbox" name="fav" value="睡觉">睡觉
<input type="checkbox" name="fav" value="吃饭" checked>吃饭
<input type="checkbox" name="fav" value="敲代码">敲代码
<input type="checkbox" name="fav" value="打游戏">打游戏
<input type="checkbox" name="fav" value="打球">打球 <br><br>
请您选择家乡:
<select name="home">
<option value="北京">北京</option>
<option value="上海">上海</option>
<option value="广东">广东</option>
<option value="西安" >西安</option>
<option value="丽江">丽江</option>
<option value="鄂尔多斯">鄂尔多斯</option>
<option value="西双版纳">西双版纳</option>
</select> <br><br>
<table align="center">
<tr>
<td align="center">个人简介:</td>
<td><textarea name="info" rows="7" cols="50"></textarea></td></tr></table><br><br>
<input type="submit" value="提交" class="tj"> <input type="reset" name="" value="重置" class="sb"></div>
</form>
获取表单的代码
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
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 'result.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>
<%
request.setCharacterEncoding("gb2312");
String account=request.getParameter("account");
out.println("账号为:"+account);
%>
<br>
<%
request.setCharacterEncoding("gb2312");
String password=request.getParameter("password");
out.println("密码为:"+password);
%> <br>
<%
request.setCharacterEncoding("gb2312");
String sex=request.getParameter("sex");
out.println("性别为:"+sex);
%> <br>
<%
request.setCharacterEncoding("gb2312");
String[] fav=request.getParameterValues("fav");
out.println("爱好为:");
for(int i=0;i<fav.length;i++){
out.println(fav[i]+" ");
}
%> <br>
<%
request.setCharacterEncoding("gb2312");
String home=request.getParameter("home");
out.println("家乡是:"+home);
%> <br>
<%
request.setCharacterEncoding("gb2312");
String[] info=request.getParameterValues("info");
out.println("个人简介是:");
for(int i=0;i<info.length;i++){
out.println(info[i]);
}
%>
</body>
</html>
request.setCharacterEncoding("gb2312");
这段代码是为了防止中文输入的东西无法获取,产生乱码。
</body>
</html>