jsp写的登陆验证界面总是出错,麻烦大家帮忙看看

喜欢象棋的小可爱 2017-10-21 08:20:10
<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>

<body>
<% String driverName="com.mysql.jdbc.Driver";
String userName="root";
String userPwd="123456";
String dbName="student";
String url="jdbc:mysql://localhost:3306/"+dbName+"?user="+userName+"&password="+userPwd+"&useUnicode=true&characterEncoding=utf-8";
Class.forName(driverName);
Connection conn=DriverManager.getConnection(url);

String sql="select * from stu_info where id=? and password=?";
PreparedStatement pstmt=conn.prepareStatement(sql);
request.setCharacterEncoding("UTF-8");

int st1=Integer.parseInt(request.getParameter("id"));//获取用户名和密码
String st2=request.getParameter("password");
pstmt.setInt(1,st1);
pstmt.setString(2,st2);

ResultSet rs=pstmt.executeQuery();
if(rs.next()){//用户存在
if(rs.getString(1).equals("pass")) {%><%
response.sendRedirect("s.jsp"); %>
<%} else { %><% //密码错误
out.print("用户名或密码错误,请重新输入!");
<a href="login.jsp">重新登陆</a>
}%><%
}%>

</body>
</html>
...全文
197 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Braska 2017-10-23
  • 打赏
  • 举报
回复
//密码错误 out.print("用户名或密码错误,请重新输入!"); %> <a href="login.jsp">重新登陆</a><% html代码要放在<%%>外面吧 }%><% }%>
usecf 2017-10-23
  • 打赏
  • 举报
回复
看看报什么错误

87,993

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧