您的位置:首页 > Web前端 > JavaScript

jsp 实现动态网页开发 登录小例子

2017-05-10 16:02 507 查看
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="index.jsp" method="post">
用户名: <input type="text" name="txtname" value="<%=request.getAttribute("name") %>"/>
密码:   <input type="password" name="txtpwd"/>
<input type="submit" value="提交"/>
<br/>
爱好<input type="checkbox" name="hello" value="跑步"/>
<input type="checkbox" name="hello" value="游泳"/>
<input type="checkbox" name="hello" value="骑马"/>
</form>

</body>
</html>


<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");

String [] jihe=request.getParameterValues("hello");
String a="";
String b="";
String c="";
if(jihe!=null){
switch(jihe.length){
case 1:
a=jihe[0];
break;
case 2:
a=jihe[0];
b=jihe[1];
break;
case 3:
a=jihe[0];
b=jihe[1];
c=jihe[2];
break;
}
}

String name = request.getParameter("txtname");
System.out.println(name);
String pwd = request.getParameter("txtpwd");
if (name.equals("中文") && pwd.equals("1")) {
//保存作用域的值
request.setAttribute("name", name);
// request.setAttribute("jihe", jihe);

request.setAttribute("jihe0", a);
request.setAttribute("jihe1",b);
request.setAttribute("jihe2", c);
//跳转
request.getRequestDispatcher("/go.jsp").forward(request,
response);
}else{
//保存值
request.setAttribute("name", name);
// request.getRequestDispatcher("/regit.jsp").forward(request,response);
//重定义
response.sendRedirect("/Day_02shili/regit.jsp");
}

if(jihe!=null){
for(String item:jihe){
out.print(item+" ");
}
}
%>

输入错误页面
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
欢迎你 <%=request.getAttribute("name") %>
<%=request.getAttribute("jihe0") %>
<%=request.getAttribute("jihe1") %>
<%=request.getAttribute("jihe2") %>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: