我正在创建一个仪表板,在仪表板中我得到req响应对象,但是当我单击链接以获取其他jsp页面时,然后在其他jsp页面中我无法获取req resp对象,请告诉我当我单击链接时,在其他jsp页面中获取请求对象。 `
<a id ="attendance" href="attendance" onclick="atten()" > Attendance</a>
<%String uname = (String)request.getAttribute("uname");
out.print(uname);
%>
<%request.getRequestDispatcher("AttendanceServlet").forward(request, response);
%>
please tell what should i write here so that when i will click on a link then it will transfer
the current page request and response to other page jsp
</li>
<li>
<a href="#">Leave</a>
</li>
<!-- <li>
<a href="#">Portfolio</a>
</li> -->strong text][1]
`
答案 0 :(得分:0)
您可以使用session
A.jsp
<% String userid="Nick";%>
<form action="B.jsp" method="post">
<%
session.setAttribute("userId", userid);
%>
<input type="submit" value="Login">
</form>
B.jsp
<%String userid = session.getAttribute("userId").toString(); %>
Hello<%=userid%>
如果您要转发整个请求/响应,则需要创建一个servlet
heres是 jsp-servlet-jsp
的简单示例