Home > front end >  Database login. Registration is no problem, don't jump to judge interface is landed
Database login. Registration is no problem, don't jump to judge interface is landed

Time:10-13

login. JSP
<% @ page language="Java" import="Java. Util. *" pageEncoding="utf-8" % & gt;
<%
String path=request. GetContextPath ();
String=basePath request. GetScheme () + "://" + request. GetServerName () + ":" + request. GetServerPort () + + "/" path;
%>




My JSP 'p126login. JSP' starting page

<meta http-equiv="pragma" content="no-cache">
<meta HTTP - equiv="cache-control" content="no - cache" & gt;
<meta HTTP - equiv="expires" content="0" & gt;
<meta HTTP - equiv="keywords" content="keyword1, keyword2, keyword3 & gt;"
<meta HTTP - equiv="description" content="This is my page" & gt;
<link rel="stylesheet" type="text/CSS" href="https://bbs.csdn.net/topics/styles.css" & gt;
-->



<body>



Login name: & lt; Input type="text" name="userid" & gt;

Password: & lt; Input type="password" name="userpass" & gt;





login_judge. JSP
<% @ page language="Java" import="Java. Util. *" pageEncoding="utf-8" % & gt;
<%
String path=request. GetContextPath ();
String=basePath request. GetScheme () + "://" + request. GetServerName () + ":" + request. GetServerPort () + + "/" path;
%>




My JSP 'p115registerok. JSP' starting page

<meta http-equiv="pragma" content="no-cache">
<meta HTTP - equiv="cache-control" content="no - cache" & gt;
<meta HTTP - equiv="expires" content="0" & gt;
<meta HTTP - equiv="keywords" content="keyword1, keyword2, keyword3 & gt;"
<meta HTTP - equiv="description" content="This is my page" & gt;
<link rel="stylesheet" type="text/CSS" href="https://bbs.csdn.net/topics/styles.css" & gt;
-->



<body>


<% @ page import="Java. SQL. *" % & gt;
<% Class. The class.forname (" com. Microsoft. Essentially. JDBC. SQLServerDriver ");
The String url="JDBC: essentially://localhost: 1433; DatabaseName=admin ";
The Connection conn=DriverManager. GetConnection (url, "news", "123456"); %>
<%
Request. SetCharacterEncoding (" utf-8 ");
String userid=request. The getParameter (" userid ");
String userpass=request. The getParameter (" userpass ");
String SQL="select * from admin. Dbo. Test the where userid=? And userpass=?" ;
PreparedStatement PSTM=conn. PrepareStatement (SQL);
PSTM. SetString (1, userid);
PSTM. SetString (2, userpass);
The ResultSet rs=PSTM. ExecuteQuery ();
{if (rs. Next ())
The session. The setAttribute (" username ", rs. Get string (" username "));
Response. SendRedirect (" p127login_success. JSP ");
}
The else {
Out. Print (" wrong man ");
The response. SetHeader (" Refresh ", "1; Url=p115register. JSP ");
}
%>




code should be no problem, don't know where is wrong, hope to have bosses see

  • Related