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");
}
%>
就会出现这个情况,完全懵逼了求大神讲解,网上搜半天找不到答案~~~
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");
}
%>
就会出现这个情况,完全懵逼了求大神讲解,网上搜半天找不到答案~~~
解决方案 »
- 想实现这样一个效果,不知道怎么实现,希望各位大侠帮帮忙
- 如何获得某个层的所有子元素
- 一个插值问题
- 请介绍一款JSP IDE
- JAVA 问题 工作经验1年以上的高手进
- 怎样在JSP中显示已经查询出来的历史记录?(仔细看下内容)
- 初学JSP,在用JavaBean创建了一个数据库连接的程序,但是在JSP中用<jsp:useBean>使用JavaBean时出现了问题。
- 访问Servlet问题,高分相送~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 请教各位大虾:如何使用前面几个页中得到的select下拉框中的值.
- 需求:领取优惠券时,优惠券有限制“总领取张数”,保证优惠券发放准确
- SpringMVC用ResponseBody返回前端Json时出的问题
- form 表单提交
String username = request.getParameter("username");
String password = request.getParameter("password");这个地方从哪有 requestsetParameter("username","xxx");吗,应该是没获取到,有的话你再检查一下两次名字是否完全相同