我开发了简单的 Web 应用程序。在一个 jsp 中,我使用 getattribute 和 set 属性从先前的 servlet 文件中获取值。我得到了这些值。但现在我想要从当前 jsp 到另一个 jsp 文件的值。使用我使用的 getattribute 和 setattribute,但值应显示为 null。
第一个jsp文件:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="javax.servlet.http.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="payment.jsp" method="POST">
<h1>Confirmation</h1>
<%
Integer amount=(Integer)request.getAttribute("amt");
String service=(String )request.getAttribute("service");
String month=(String )request.getAttribute("month");
Integer day=(Integer)request.getAttribute("day");
String time=(String)request.getAttribute("time");
String city=(String)request.getAttribute("city");
out.println("<center>");
out.println("<table><tr>");
out.println("<td><h2>Service:"+service+"</td></tr>");
out.println("<tr><td><h2>Month:"+month+"</td></tr>");
out.println("<tr><td><h2>Date:"+day+"</td></tr>");
out.println("<tr><td><h2>Time:"+time+"</td></tr>");
out.println("<tr><td><h2>City:"+city+"</td></tr>");
out.println("<tr><td><h2>Total Amount:Rs."+amount+"</td></tr>");
out.println("</center>");
request.setAttribute("amt",amount);
%>
<center>
<input type="submit" value="Confirm"></input>
</center>
</form>
</body>
</html>
付款.jsp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>Select bank</h2>
<%!Integer money;%>
<%
if(request.getAttribute("amt")!=null)
{
money=(Integer) request.getAttribute("amt");
out.println(""+money);
}
%>
</body>
</html>