Jakarta ee HttpServletRequest.getAttribute()在jsp页面上给出空值
您好,我正在尝试将数据从servlet传递到jsp页面,但得到一个空值。 请告诉我哪里出错了? 这是我的密码: MyConnection.javaJakarta ee HttpServletRequest.getAttribute()在jsp页面上给出空值,jakarta-ee,servlets,Jakarta Ee,Servlets,您好,我正在尝试将数据从servlet传递到jsp页面,但得到一个空值。 请告诉我哪里出错了? 这是我的密码: MyConnection.java public void doGet (HttpServletRequest inRequest, HttpServletResponse outResponse) throws ServletException, IOException { inRequest.se
public void doGet (HttpServletRequest inRequest,
HttpServletResponse outResponse) throws ServletException,
IOException {
inRequest.setAttribute ("ST", "QWERTY");
RequestDispatcher dispatcher = inRequest.getRequestDispatcher ("/index.jsp");
out.print ("\ n" + dispatcher);
dispatcher.forward (inRequest, outResponse);
}
index.jsp
<% @ page contentType = "text / html" pageEncoding = "UTF-8"%>
<% @ page language = "java" import = "java.util. *"%>
<! DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> JSP Page </ title>
</ head>
<body>
<form action="MyConnection" name = "myForm" method="Get">
<% = (String) request.getAttribute ("ST")%>
<% out.println (request.getAttribute ("ST"));%>
</ form>
</ body>
</ html>
JSP页面
浏览器中的地址是JSP的地址,因此执行JSP。要执行servlet,您必须将servlet的地址放在地址栏中。您可能根本不调用servlet,而是直接转到JSP。检查浏览器地址栏中的地址。顺便说一句,servlet中JSP的路径可能是错误的:我怀疑JSP文件名是否以空格开头。另外,完全忘记Scriptlet。使用JSP EL和JSTL:${ST}
。文件名不以空格开头,这是copy pase错误。浏览器中的地址下一步:“我需要使用的servlet,这是一项任务)