checklogin.jsp
来自「此资源是jsp应用开发 邓子云等编写的一书里的源代码」· JSP 代码 · 共 43 行
JSP
43 行
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*,javax.naming.*,javax.sql.DataSource" %>
<%
//------接收请求参数------
String oaUserName=request.getParameter("oaUserName");
String oaUserPassword=request.getParameter("oaUserPassword");
//------如果接收数据有误------
if(oaUserName==null||oaUserPassword==null||
oaUserName.length()==0||oaUserPassword.length()==0)
response.sendRedirect("login.jsp");
//------构造查询数据库的SQL语句-----
String sqlStr=new String("select * from oaUser where "+
"oaUserName=? and oaUserPassword=?");
//------得到数据库连接------
Context initCtx = new InitialContext();
Context ctx = (Context) initCtx.lookup("java:comp/env");
Object obj = (Object) ctx.lookup("jdbc/sqlserver");
DataSource ds = (javax.sql.DataSource)obj;
Connection conn = ds.getConnection();
//------查询数据------
PreparedStatement preSQLSelect=conn.prepareStatement(sqlStr,ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
oaUserName=new String(oaUserName.getBytes("ISO-8859-1"));
preSQLSelect.setString(1,oaUserName);
oaUserPassword=new String(oaUserPassword.getBytes("ISO-8859-1"));
preSQLSelect.setString(2,oaUserPassword);
ResultSet rs=preSQLSelect.executeQuery();
if(rs==null){
response.sendRedirect("login.jsp");
}else{
rs.next();
int i=rs.getRow();
if(i>=1){
rs.first();
session.setAttribute("oaUserName",rs.getString("oaUserName"));
session.setAttribute("oaUserTrueName",rs.getString("oaUserTrueName"));
session.setAttribute("oaUserId",rs.getString("oaUserId"));
session.setAttribute("departmentId",rs.getString("departmentId"));
}
response.sendRedirect("../index.jsp");
}
if(conn!=null)
conn.close();
%>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?