问一个有关jsp的问题,求半个忙

J2EE 码拜 9年前 (2016-05-15) 1011次浏览
a、项目包
问一个有关jsp的问题,求半个忙
b、html页面,本人这里是login。html
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<title>login.html</title>
<meta http-equiv=”keywords” content=”keyword1,keyword2,keyword3″>
<meta http-equiv=”description” content=”this is my page”>
<meta http-equiv=”content-type” content=”text/html; charset=UTF-8″>

<!–<link rel=”stylesheet” type=”text/css” href=”./styles.css”>–>
</head>

<body>
<form name=”f1″ id=”f1″ action=”action/do_login.jsp” method=”post”>
<table border=”0″>
<tr>
<td>Login:</td>
<td><input type=”text” name=”username” id=”username”></td>
</tr>
<tr>
<td>Password:</td>
<td><input type=”password” name=”password” id=”password”></td>
</tr>
<tr>
<td colspan=”2″ align=”center”><input type=”reset” value=”Reset” name=”button1″><input type=”submit”></td>
</tr>
</table>
</form>
</body>
</html>
b、本人的action下的do_login.jsp代码
<%@ page language=”java” import=”java.util.*” pageEncoding=”UTF-8″%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
%>
<%
request.setCharacterEncoding(“UTF-8”);
response.setCharacterEncoding(“UTF-8”);
%>
<%
String username=request.getParameter(“username”);
String password=request.getParameter(“password”);

System.out.println(“username”+username);
System.out.println(“password”+password);
if(username.equals(“zenglingzhuang”) && password.requals(“123456”)){
request.getRequestDispatcher(“../admin/welcome.jsp”).forward(request.response);
}else{
response.sendRedirect(“../login.html”);
}
%>
c、本人的admin下的welcome.jsp代码
<%@ page language=”java” import=”java.util.*” pageEncoding=”UTF-8″%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
%>
<%
request.setCharacterEncoding(“UTF-8”);
response.setCharacterEncoding(“UTF-8”);
%>
<%
String username=request.getParameter(“username”);
%>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<base href=”<%=basePath%>”>

<title>My JSP “welcome.jsp” starting page</title>

<meta http-equiv=”pragma” content=”no-cache”>
<meta http-equiv=”cache-control” content=”no-cache”>
<meta http-equiv=”expires” content=”0″>
<meta http-equiv=”keywords” content=”keyword1,keyword2,keyword3″>
<meta http-equiv=”description” content=”This is my page”>
<!–
<link rel=”stylesheet” type=”text/css” href=”styles.css”>
–>
</head>

<body>
<h1>[<%=username %>],欢迎你登录后台 </h1>
</body>
</html>
本人的问题是,本人不清楚为什么加上这行代码:
request.getRequestDispatcher(“../admin/welcome.jsp”).forward(request.response)一提交;就出现以下错误
问一个有关jsp的问题,求半个忙

解决方案

20

do_login.jsp的16行 if(username.equals(“zenglingzhuang”) && password.requals(“123456”)){多了个r

20

do_login.jsp中equals写错了,写成了requals
request.getRequestDispatcher(“../admin/welcome.jsp”).forward(request.response),这里的意思是请求转发,就是把当前的页面的request,带到welcome.jsp页面中

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明问一个有关jsp的问题,求半个忙
喜欢 (0)
[1034331897@qq.com]
分享 (0)