我尝试学习会话隐式对象。请检查。在index.jsp
我创建了一个表单。点击提交按钮后,它将重定向到welcome.jsp
。在welcome.jsp
我正在创建会话属性,在同一页面中我们重定向到second.jsp
。在second.jsp中,我们将通过会话获取名称。但是在 welcom.jsp文件中出错了。找不到符号:变量位置:class simplyfiedJSPServlet 。
的index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1> This for getting session implicit object </h1>
<form action="welcome3.jsp">
<input type="text" name="uname">
<input type="submit" value="go"><br/>
</form>
</body>
</html>
的welcome.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String name=request.getParameter("uname");
out.print("Welcome"+name);
session.setAttribute("user", name);
<a href ="second.jsp" > second jsp </a>
%>
</body>
</html>
second.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String name=(String )session.getAttribute("user");
%>
</body>
</html>
的web.xml
<web-app>
<error-page>
<error-code> 500</error-code>
<location> /error.jsp</location>
</error-page>
</web-app>
答案 0 :(得分:1)
你在java代码中有html标签,
<%
String name=request.getParameter("uname");
out.print("Welcome"+name);
session.setAttribute("user", name);
<a href ="second.jsp" > second jsp </a> // html anchor tag
%>
应该在它之外,
<a href ="second.jsp" > second jsp </a>