jsp页面中用Httpsession的问题
我的一个loginok.jsp文件内容如下<%@pageimport="javax.servlet.*,javax.servlet.http.*"contentType=...
我的一个loginok.jsp文件内容如下
<%@ page import="javax.servlet.*,javax.servlet.http.*" contentType="text/html;charset=gb2312" %>
<html>
<head>
<title>
LoingokPage
</title>
</head>
<body>
<%
Httpsession session=request.getSession();
username=(String)session.getAttribute("username");
if(username==null)
response.SendRedirect("/registerLogin/login.html");
else
{
%>
<h1><%= username %> Welcome You to here</h1>
<%
}
%>
</body>
</html>
运行后出现的错误是:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 11 in the jsp file: /registerLoginWeb/loginok.jsp
username cannot be resolved
8: <body>
9: <%
10: HttpSession session1=request.getSession();
11: username=(String)session1.getAttribute("username");
12: if(username==null)
13: response.SendRedirect("/registerLogin/login.html");
14: else
An error occurred at line: 12 in the jsp file: /registerLoginWeb/loginok.jsp
username cannot be resolved
9: <%
10: HttpSession session1=request.getSession();
11: username=(String)session1.getAttribute("username");
12: if(username==null)
13: response.SendRedirect("/registerLogin/login.html");
14: else
15: {
An error occurred at line: 13 in the jsp file: /registerLoginWeb/loginok.jsp
The method SendRedirect(String) is undefined for the type HttpServletResponse
10: HttpSession session1=request.getSession();
11: username=(String)session1.getAttribute("username");
12: if(username==null)
13: response.SendRedirect("/registerLogin/login.html");
14: else
15: {
16: %>
An error occurred at line: 17 in the jsp file: /registerLoginWeb/loginok.jsp
username cannot be resolved
14: else
15: {
16: %>
17: <h1><%= username %> Welcome You to here</h1>
18: <%
19: }
20: %> 展开
<%@ page import="javax.servlet.*,javax.servlet.http.*" contentType="text/html;charset=gb2312" %>
<html>
<head>
<title>
LoingokPage
</title>
</head>
<body>
<%
Httpsession session=request.getSession();
username=(String)session.getAttribute("username");
if(username==null)
response.SendRedirect("/registerLogin/login.html");
else
{
%>
<h1><%= username %> Welcome You to here</h1>
<%
}
%>
</body>
</html>
运行后出现的错误是:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 11 in the jsp file: /registerLoginWeb/loginok.jsp
username cannot be resolved
8: <body>
9: <%
10: HttpSession session1=request.getSession();
11: username=(String)session1.getAttribute("username");
12: if(username==null)
13: response.SendRedirect("/registerLogin/login.html");
14: else
An error occurred at line: 12 in the jsp file: /registerLoginWeb/loginok.jsp
username cannot be resolved
9: <%
10: HttpSession session1=request.getSession();
11: username=(String)session1.getAttribute("username");
12: if(username==null)
13: response.SendRedirect("/registerLogin/login.html");
14: else
15: {
An error occurred at line: 13 in the jsp file: /registerLoginWeb/loginok.jsp
The method SendRedirect(String) is undefined for the type HttpServletResponse
10: HttpSession session1=request.getSession();
11: username=(String)session1.getAttribute("username");
12: if(username==null)
13: response.SendRedirect("/registerLogin/login.html");
14: else
15: {
16: %>
An error occurred at line: 17 in the jsp file: /registerLoginWeb/loginok.jsp
username cannot be resolved
14: else
15: {
16: %>
17: <h1><%= username %> Welcome You to here</h1>
18: <%
19: }
20: %> 展开
3个回答
展开全部
额,你的username 没有定义类型啊,这样:
String username = (String)session.getAttribute("username");
然后,这个session 是JSP页面的内部对象,不需要再定义。
最后,你的 response.SendRedirect(url)错了,注意是
这样写的 response.sendRedirect("/registerLogin/login.html");
//******************修改后为***************************
<%@ page import="javax.servlet.*,javax.servlet.http.*"
contentType="text/html;charset=gb2312" %>
<html>
<head>
<title>
LoingokPage
</title>
</head>
<body>
<%
String username=(String)session.getAttribute("username");
if(username==null)
response.sendRedirect("/registerLogin/login.html");
else
{
%>
<h1><%= username %> Welcome You to here</h1>
<%
}
%>
</body>
</html>
String username = (String)session.getAttribute("username");
然后,这个session 是JSP页面的内部对象,不需要再定义。
最后,你的 response.SendRedirect(url)错了,注意是
这样写的 response.sendRedirect("/registerLogin/login.html");
//******************修改后为***************************
<%@ page import="javax.servlet.*,javax.servlet.http.*"
contentType="text/html;charset=gb2312" %>
<html>
<head>
<title>
LoingokPage
</title>
</head>
<body>
<%
String username=(String)session.getAttribute("username");
if(username==null)
response.sendRedirect("/registerLogin/login.html");
else
{
%>
<h1><%= username %> Welcome You to here</h1>
<%
}
%>
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个页面没有错 错误在login.html里 你检查一下login页面
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
路径的问题!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询