JSP作业,求大神写代码!编制一个简单的登录界面。
编制一个简单的登录界面,表单中包含用户名和密码,密码用掩码形式,提交后在网页中显示用户名和密码内容,注意要处理中文乱码问题。最好能说明一下运行方法谢谢!!!...
编制一个简单的登录界面,表单中包含用户名和密码,密码用掩码形式,提交后在网页中显示用户名和密码内容,注意要处理中文乱码问题。
最好能说明一下运行方法谢谢!!! 展开
最好能说明一下运行方法谢谢!!! 展开
2个回答
2014-12-15
展开全部
第一个页面命名:Login.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Login.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<br><br><br><br><br>
<form method="post" action="checkLogin.jsp">
<table align="center" width="300">
<tr>
<td>用户名:</td>
<td><input type="text" name="username" size="20"></td>
</tr>
<tr>
<td>密 码:</td>
<td><input type="password" name="password" size="20"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="登录" >
<input type="reset" value="取消" >
</td>
</tr>
</table>
</form>
</body>
</html>
第二个页面命名:checkLogin.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 'checkLogin.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>
<% String username,password;
request.setCharacterEncoding("utf-8");
username=request.getParameter("username");
password=request.getParameter("password");
if(username!=null&&password!=null){
out.println("<h2>用户名:<font color='blue'><b>"+username+"</b></font><br><h2>");
out.println("<h2>密码:<font color='blue'><b>"+password+"</b></font><h2>");
}
else{
out.println("<h2>请填写用户名和密码!</h2><br>3秒钟后,自动跳转到登入页面...");
response.setHeader("refresh","3;url=Login.html");
}
%>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Login.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<br><br><br><br><br>
<form method="post" action="checkLogin.jsp">
<table align="center" width="300">
<tr>
<td>用户名:</td>
<td><input type="text" name="username" size="20"></td>
</tr>
<tr>
<td>密 码:</td>
<td><input type="password" name="password" size="20"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="登录" >
<input type="reset" value="取消" >
</td>
</tr>
</table>
</form>
</body>
</html>
第二个页面命名:checkLogin.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 'checkLogin.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>
<% String username,password;
request.setCharacterEncoding("utf-8");
username=request.getParameter("username");
password=request.getParameter("password");
if(username!=null&&password!=null){
out.println("<h2>用户名:<font color='blue'><b>"+username+"</b></font><br><h2>");
out.println("<h2>密码:<font color='blue'><b>"+password+"</b></font><h2>");
}
else{
out.println("<h2>请填写用户名和密码!</h2><br>3秒钟后,自动跳转到登入页面...");
response.setHeader("refresh","3;url=Login.html");
}
%>
</body>
</html>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我帮你写吧 ·
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |