我想要一个名为home.jsp的jsp重定向到欢迎jsp.It无法正常工作。请告诉我我哪里出错。下面有三个简单的jsp。请帮帮我。我认为有一些错误连接数据库
home.jsp-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome</title>
</head>
<body>
<form action='login.jsp' method="post">
<div>
<table>
<tr>
<td>USERNAME</td>
<td><input type="text" id="usernameID"/></td>
</tr>
<tr>
<td>PASSWORD</td>
<td><input type="text" id=passwordID /></td>
</tr>
<tr>
<td></td>
<td><input type="button" id="loginId" value="LOGIN" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
login.jsp-
<%@ page import="java.sql.*" %>
<%Class.forName("oracle.jdbc.driver.OracleDriver"); %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:8081:XE", "SYSTEM", "Lalita");
PreparedStatement ps=(PreparedStatement)con.createStatement();
String id=request.getParameter("usernameID");
String password=request.getParameter("passwordID");
ResultSet rs=ps.executeQuery("select * from USERCREDENTIALS");
String rsID=rs.getString(1);
String rsPassword=rs.getString(2);
out.println(rsID);
if(id==rsID && password==rsPassword )
response.sendRedirect("./welcome.jsp");
%>
</body>
</html>
welcome.jsp-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
hiiiiiiiiiiiiiiiiiiiiiiii
</body>
</html>
&#13;
答案 0 :(得分:0)
您尝试发送重定向的目录是错误的 试试这个......
response.sendRedirect("../welcome.jsp");
这应该有用。