packagecom.control;importjava.io.*;importjava.sql.*;importjavax.servlet.*;importjavax.servlet.http.*;importcom.model.BookBean;publicclassUserLoginServletextendsHttpServle...
package com.control;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.model.BookBean;
public class UserLoginServlet extends HttpServlet {
Connection conn;
public void init() {
String driver="com.microsoft.jdbc.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:microsoft.sqlserver://localhost:1433:DatabaseName=网上书店";
String username="admin";
String password="admin";
//con = DriverManager.getConnection(dburl);
try{
Class.forName(driver); //加载数据库驱动程序
//创建数据库连接对象
conn = DriverManager.getConnection(
url,username,password);
}catch(ClassNotFoundException e1){
}catch(SQLException e2){}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session=request.getSession(true);
String u_name = request.getParameter("u_name");
String u_password = request.getParameter("u_password");
String location="";
String sql="SELECT u_password FROM B_user where u_name=?";
PreparedStatement pstmt = conn.prepareStatement(sql);
request.setCharacterEncoding("GB2312");
pstmt.setString(1,u_name);
ResultSet rst = pstmt.executeQuery();
response.setContentType("text/html;charset=gb2312");
PrintWriter out=response.getWriter();
while(rst.next()){
String password=rst.getString("u_password");
求帮忙改 QAQ
展开