jsp页面的数据传到html页面如何接收?

login.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<script>
	function getInfo(){
		var pos,parastr,para;
		//获取链接
		var hrefStr=window.location.href;
		pos=hrefStr.indexOf("?");
		parastr=hrefStr.substring(pos+1);
		para=parastr.split("&");
		//得到name=?&password=?
		var name=para[0].split("=");
		var password=para[1].split("=");
		//给输入框赋值
		document.form1.username.value=name[1];
		document.form1.password.value=password[1];
	}
</script>
<body onload="getInfo()">
	<form action="check.jsp" method="post" name="form1">
		用户名:<input type="text" name="username" id="username"/><br/>
		密码:<input type="password" name="password" id="password" /><br/>
		<input type="submit" value="登录" />
	</form>
	<!-- 相对路径 -->
	<!-- <img src="../img/1.jpg" width="100px" height="100px"/> -->
	<!-- 绝对路径 -->
	<!-- <img src="http://127.0.0.1:8080/dur3_ex/img/1.jpg" width="100px" height="100px"/> -->
</body>
</html>

check,jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.wance.dao.UserDao"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

	<%
		//接收数据
		String name = request.getParameter("username");
		String password = request.getParameter("password");

		UserDao ud = new UserDao();
		boolean flag = ud.check(name, password);
		if (flag) {
			out.println("<html><body><label>欢迎'" + name + "'访问本页面,你此次的登录时间为:'"
					+ new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()) + "'</lable></body></html>");
		} else {
			out.println("<script>alert('用户名或密码错误')</script>");
			String s = "login.html?name=" + name + "&password=" + password;
			out.println("<script>location.href='" + s + "'</script>");
		}
	%>
</body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章