问题描述
- jsp连接数据库第一步就出现问题
-
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">用户登录
<% try
{ Class.forName("com.mysql.jdbc.Driver");}
catch(Exception e){
e.printStackTrace();
}
Connection conn;
ResultSet rs;
String sql;
String username=request.getParameter("in_user");
String password=request.getParameter("in_password");
try
{
String database="mydb";
String url="jdbc:mysql://localhost/"+database;
conn=DriverManager.getConnection(url,"root","root");
PreparedStatement pstmt=null;
sql="select * from user where username=? and password=?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,username);
pstmt.setString(2,password);
rs=pstmt.executeQuery();
if(rs.next())
{ request.getSession(true);
session.setAttribute("username",username);
session.setAttribute("password",password);
session.setAttribue("enter","true");
response.sendRedirect("index.jsp");
}
else{out.println("您输入的信息有误,请重试!");response.setHeader("refresh", "5;URL=Login.jsp");}}
catch(Exception e){
out.print("系统出错,请重试");
}
%>
如果你的浏览器不支持自动跳转,请点击此处HTTP ERROR 500
Problem accessing /MyFirstWeb/login.jsp. Reason:
PWC6033: Error in Javac compilation for JSP
PWC6199: Generated servlet error:
string:///login_jsp.java:6: ??? com.mysql.jdbc ???PWC6197: An error occurred at line: 13 in the jsp file: /login.jsp
PWC6199: Generated servlet error:
string:///login_jsp.java:83: ?????
??? ?? setAttribue(java.lang.String,java.lang.String)
??? ?? javax.servlet.http.HttpSessionCaused by:
org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSPPWC6199: Generated servlet error:
string:///login_jsp.java:6: ??? com.mysql.jdbc ???PWC6197: An error occurred at line: 13 in the jsp file: /login.jsp
PWC6199: Generated servlet error:
string:///login_jsp.java:83: ?????
??? ?? setAttribue(java.lang.String,java.lang.String)
??? ?? javax.servlet.http.HttpSession****##** 貌似第一步Class.forName就错了,哪里错了了,我在项目右键properties-----java buile path------add external jars里加入了jmysql-connector-java-5.0.6-bin.jar啊 求大虾指点
解决方案
你的session定义在哪里,上面的代码上没有看到。如果没有定义,将上面的request.getSession(true);改成HttpSession = request.getSession(true);
解决方案二:
你的session定义在哪里,上面的代码中没有看到,如果没有的话,把request.getSession(true);改成HttpSession session = request.getSession(true);
解决方案三:
到底是什么问题啊 求大虾解答0。0