代码怎么改,这个是跳转都一样的,要用数据库
<body>
<%
String username=request.getParameter("username");
String pwd=request.getParameter("pwd");
String role=request.getParameter("role");
Class.forName("org.gjt.mm.mysql.Driver");
String url = "jdbc:mysql://localhost:3306/bookmanage?user=root&password=caijunsen&useUnicode=true&characterEncoding=utf-8";// ݿ
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "select * from users where username='"+username+"' and pwd='"+pwd+"' and role='"+role+"'";
ResultSet result = stmt.executeQuery(sql);
if(result.next()){
session.setAttribute("username",username);
%>
<jsp:forward page="addBooks.jsp"></jsp:forward>
<%
} else{
%>
<jsp:forward page="login.jsp"></jsp:forward>
<%
}
%>
</body>
怎么判断
不应该是判断role吗
追答那就这样写,你试试
if (result.next()) {这个可以再加,就想知道要怎么判断
追答简单一点,用户表中加个字段isAdmin,根据这个判断;另外可以引入角色的设计,这个就要多加几张表,建议先用第一种完成,后续再优化
If else要怎么写