package dao;import java.sql.*;public class Dao {
private String dri="com.mysql.jdbc.Driver";
private String url="jdbc:mysql://localhost:3306/Tourism";
private String Id="root";
private String pwd="root";
private Connection conn=null;

/**
 * 连接数据库
 */
public void getconntion(){
if(conn==null){
try {
Class.forName(dri);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 try {
conn=DriverManager.getConnection(url,Id,pwd);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
 * 查询
 */
public ResultSet executeQuery(String sql){
getconntion();
ResultSet rs=null;
try {
Statement state=conn.createStatement();
rs=state.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
}
数据库的账号和密码是admin和123
这个是登录的方法
然后在main方法里测试一切正常但是在jsp页面调用的时候
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@ page import="impl.Tri" %>
<%@ page import="impl.Tribu" %>
<%@ page import="dao.Dao" %>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<% request.setCharacterEncoding("utf-8"); %>
<%
Tri tri = new Tribu();
String username = request.getParameter("username");
String password = request.getParameter("password");
if(tri.login(username, password)){
session.setAttribute("username", username);
request.getRequestDispatcher("index.jsp").forward(request, response);
}else{
out.print("账号或密码错误,3秒后返回登录界面!");
response.setHeader("refresh","3;url=login.jsp");
}
 %>
就会出现这个情况,完全懵逼了求大神讲解,网上搜半天找不到答案~~~