<%--程序input.jsp--%> <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <html> <head> <title>输入页面</title> </head> <request.setCharacterEncoding("UTF-8");> <body> <request.setCharacterEncoding("UTF-8");> <form action="sum.jsp"method="post"> <table> <tr><td>数据1:</td><td><input name="shuju1"></td></tr> <tr><td>数据2:</td><td><input name="shuju2"></td></tr> <tr><td colspan="2"align="center"><input type="submit"value="提交"></td></tr> </table> </form> </body> </html> <%--程序sum.jsp--%> <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@page import="java.lang.*" %> <html> <head> <title>和页面</title> </head> <body> <%String str1=request.getParameter("shuju1"); String str2=request.getParameter("shuju2"); double s1=Double.parseDouble(str1); double s2=Double.parseDouble(str2); double s3=s1+s2; request.setAttribute("st1",s1); request.setAttribute("st2",s2); request.setAttribute("st3",s3); %> <jsp:forward page="output.jsp"/> </body> </html> <%--程序output.jsp--%> <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <html> <head> <title>输出页面</title> </head> <body> 利用getAttribute方法获取利用setAttribute方法保存的值,并显示!<br> <%Double a1=(Double)request.getAttribute("st1"); Double a2=(Double)request.getAttribute("st2"); Double a3=(Double)request.getAttribute("st3"); %> <%=a1 %>+<%=a2 %>=<%=a3 %><br> 利用getParameter方法获取请求参数,并显示!<br> <%String s1=request.getParameter("shuju1"); String s2=request.getParameter("shuju2"); %> <%=s1 %>+<%=s2 %>=<%=a3 %><br> </body> </html>