标签:style blog io color os ar java for sp
1 <%@ page language="java" import="java.util.*" pageEncoding="GBK"%> 2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 3 <html> 4 <head> 5 <title>My JSP ‘index.jsp‘ starting page</title> 6 </head> 7 <body> 8 <form id="form1" name="form1" method="post" action="session.jsp"> 9 您的名字是: <input type="text" name="name" /> 10 <input type="submit" name="Submit" value="提交" /> 11 </form> 12 </body> 13 </html>
1 <%@ page language="java" import="java.util.*" pageEncoding="GBK"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 %> 6 7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 8 <html> 9 <head> <title>My JSP ‘session.jsp‘ starting page</title> </head> 10 <body> 11 <% 12 String name = request.getParameter("name"); //获取用户填写的用户名 13 session.setAttribute("name",name); //将用户名保存在session对象中 14 %> 15 <form id="form1" name="form1" method="post" action="result.jsp"> 16 您的名字是: 17 <%=name%> 18 您最喜欢去的地方是:<input type="text" name="address" /> 19 <input type="submit" name="Submit" value="提交" /> 20 </form> 21 </body> 22 </html>
1 <%@ page language="java" import="java.util.*" pageEncoding="GBK"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 %> 6 7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 8 <html> 9 <head> <title>My JSP ‘result.jsp‘ starting page</title></head> 10 <body> 11 <% 12 String name = (String)session.getAttribute("name"); //获取保存在session范围内的对象,其实第一次取得ssesion后随便那个网页都可以取得 13 14 String solution = request.getParameter("address"); //获取用户输入的最想去的地方 15 %> 16 <form id="form1" name="form1" method="post" action=""> 17 显示答案 18 您的名字是: <%=name%> <!-- 将用户输入的用户名在页面中显示 --> 19 您最喜欢去的地方是:<%=solution%><!-- 将用户输入的最想去的地方在页面中显示 --> 20 </form> 21 </body> 22 </html>
标签:style blog io color os ar java for sp
原文地址:http://www.cnblogs.com/huchap/p/4063679.html