jsp页面转发forward的使用

来源:互联网 发布:魔兽世界70数据库 编辑:程序博客网 时间:2024/05/17 17:17

1:页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<% request.setCharacterEncoding("utf-8");%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>主页面</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
  </head>
  <body>
    <div align="center">
      <table>
         <tr>
          <th>主页面</th>
         </tr>
      </table>
    </div>
    <jsp:forward page="subPage.jsp">
    <jsp:param value="John" name="userName"/>
     <jsp:param value="10086" name="password"/>
      <jsp:param value="北京海淀" name="address"/>
      </jsp:forward>
  </body>
</html>


2:跳转后的页面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<% request.setCharacterEncoding("utf-8");%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>子页面</title>
     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
  </head>
  <body>
  <%
    String userName=request.getParameter("userName");
     String password=request.getParameter("password");
      String address=request.getParameter("address");
   %>
    <div align="center">
    <table>
      <tr>
      <th>子页面:人员信息</th>
      </tr>
      <tr>
       <td>用户名:<%=userName%></td>
      </tr>
      <tr>
       <td>密&nbsp;码:<%=password%></td>
      </tr>
       <tr>
       <td>地址:<%=address%></td>
      </tr>
    </table>
    </div>
  </body>
</html>

0 0