登录界面:
找到。jsp:
& lt; % @page contentType=" text/html ",进口=" java.sql。*”pageEncoding=" utf - 8 " %在
& lt; html>
& lt; head> & lt; title>登录& lt;/title> & lt;/head>
& lt; body>
& lt; %
request.setCharacterEncoding (“utf - 8”);
,,字符串id=request.getParameter (" id ");
,passwd=request.getParameter,字符串(“passwd”);
,,布尔标志=false;
,,PreparedStatement sql=零;,
,,ResultSet rs=零;
,康涅狄格州,连接=零;
%在
& lt; %,
,,,,,,字符串driverName=癱om.mysql.jdbc.Driver”;,,,
,,,,,,字符串的用户名="根",
,,,,,,字符串userPwd=癮aa312”;
,,,,,,字符串dbName="学生",
,,,,,,字符串url1=" jdbc: mysql://localhost: 3306/" + dbName;
,,,,,,字符串url2=" ?用户=" +用户名+”,密码=" + userPwd;
,,,,,,字符串url3=", useUnicode=true& characterEncoding=utf - 8”;
,,,,,,字符串url=url1 + url2 + url3;
,,,,,,forname (driverName);//加载驱动,
,,,,,,康涅狄格州=DriverManager.getConnection (url、用户名、userPwd);,
,,sql=康涅狄格州。prepareStatement (“select * from students_info id=?passwd=?”);
,,sql.setString (id),
,,sql.setString (2, passwd);
,,rs=sql.executeQuery ();
,,如果(rs.next ()) {,
,,国旗=true;
,,,}
,,rs.close ();
,,sql.close ();
,,conn.close ();
,%在
& lt; !——判断是否是正确的登录用户,在
& lt; %如果(标志==true)
{%在
& lt; jsp:转发页面=皊.jsp”/祝辞
& lt; %}其他response.sendRedirect (“f.jsp”); %在
& lt;/body>
& lt;/html>
s.jsp:
& lt; % @页面语言=进口=" java.util“java”。*”pageEncoding=" utf - 8 " %在
& lt; %
字符串路径=request.getContextPath ();
字符串basePath=request.getScheme () +”://? request.getServerName () + ": " + request.getServerPort() +路径“/?
%在
& lt; !DOCTYPE HTML公共”——//W3C//DTD HTML 4.01过渡//EN "在
& lt; html>
,& lt; head>
,,& lt;基地href=" https://www.yisu.com/zixun/"在
,,,
,,& lt; title> JSP的欢迎。jsp的起始page
,,,
& lt;元http-equiv=霸幼ⅰ蹦谌?皀o - cache”在
& lt;元http-equiv=癱ache - control”内容=皀o - cache”在
& lt;元http-equiv=暗狡凇蹦谌?" 0 "比;,,
& lt;元http-equiv=肮丶省蹦谌?発eyword1、keyword2 keyword3”在
& lt;元http-equiv=懊枋觥蹦谌?罢馐俏业囊趁妗痹?/p>
& lt; !——
& lt;链接rel="样式表" type=" text/css " href=" https://www.yisu.com/zixun/styles.css "在
——在
,& lt;/head>
,,
,& lt; body>
,,& lt; %字符串名称=request.getParameter(“用户名”);%在
,,欢迎你,& lt; %=%比名称;成功登录!
,& lt;/body>
& lt;/html>
f.jsp:
& lt; % @页面语言=进口=" java.util“java”。*”pageEncoding=" utf - 8 " %在
& lt; !DOCTYPE HTML公共”——//W3C//DTD HTML 4.01过渡//EN "在
& lt; html>
,,
,& lt; body>
,,,对不起,你的信息有误,请重新登录! & lt; br/祝辞
,,,action=& lt;形式”登录。jsp”方法=" post "在
,,& lt;输入类型="提交" value=" https://www.yisu.com/zixun/返回登录”/祝辞
,,,& lt;/form>
,& lt;/body>
& lt;/html>