我在我的jsp中设置 request.getAttribute 如下
<%@ 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">
<%
request.setAttribute("name", "anita");
%>
<%=request.getAttribute("name") %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="POST" action="QnAAuthServlet">
<input type="hidden" name="orgName" value="SENDFORBOB"></input>
<input type="submit"></input>
</form>
</body>
</html>
我也可以在我的 JSP 中打印它
我正在尝试在我的 servlet 中请求 request.getAttribute,如下所示
public class QnAAuthServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public QnAAuthServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
enter code here
String name = (String) request.getAttribute("name");
System.out.println("name = " + name);
}
}
但在我的 servlet 中,名称始终为空。请有人帮我解决这个问题。