两个jsp页面间带参跳转

a.jsp页面 中 通过超链接跳到 b.jsp页面:
通过 a标签 中href=…?a=1&b=2 携带参数跳转。
那么在b页面中如何取出所携带的参数a、b中的值?
就我所知,有两种方式:

  第一种:
         在b.jsp页面中,直接使用EL表达式,${param.a}  、${param.b};即可取出参数的值
         其中的 param表示参数。
   第二种:通过request.getParameter()的方式。如下
   
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML>
<html>
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <!--上面的三个meta元标签必须放在最前面,别的东西必须在它们三的后面-->
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <script src="../js/jquery-3.2.1.min.js"></script>这个文件要在下面这个文件之前导入,不然报错
    <script src="../js/bootstrap.min.js"></script>
    <title>main.jsp</title>
    
  </head>
  <body>
     	<h1>main.jsp</h1>

     	此时登录账户为:${sessionScope.login.loginname }
      	<%
        //下面的param是从index.jsp页面(相当于我在上面举例用的a.jsp页面)传过来的参数,这里的param并没有别的意思,只是我在index.jsp页面的超链接中起的名字就叫param。仅仅只是一个名字而已。
     	String param=request.getParameter("param");

     	param=new String(param.getBytes("ISO8859_1"), "utf-8");//对可能出现的乱码进行处理
     	String [] s=param.split("。");
     	String [][]a=new String[s.length][2];
     	int i=0; 
     	for(String str:s){
     		 String [] h=str.split("@");
     		 a[i][0]=h[0];
     		 a[i][1]=h[1];
     		 i++;
     	}
     	request.setAttribute("a", a);

	%>
     	
      	 <br/>	 <br/>	 <br/>	 <br/>	 <br/>

         //会根据用户权限 动态生成权限路径的按钮
      	 <div align="center">
	     	 <c:forEach var="i" begin="0" end="${fn:length(a)-1 }">
	     	       <c:if test="${requestScope.a[i][0] == '1'}">
	     	             <a href="${requestScope.a[i][1] }" target="abc"><button class="btn btn-info">普通员工路径</button></a>
	     	       </c:if>
	     	        <c:if test="${requestScope.a[i][0] == '2'}">
	     	             <a href="${requestScope.a[i][1] }" target="abc"><button class="btn btn-warning">部门经理路径</button></a>
	     	       </c:if>
	     	        <c:if test="${requestScope.a[i][0] == '3'}">
	     	             <a href="${requestScope.a[i][1] }" target="abc"><button class="btn btn-success">总经理路径</button></a>
	     	       </c:if>
	     	       
	     	 </c:forEach>
     	 </div>

     	 <div align="center"> 
     	 	 <iframe  name="abc"  width="90%" height="600" frameborder="1"></iframe>
     	 </div>
     	 
     	 
     	 
     	
  </body>

下图就是这个项目中 XxxxAction类中
在这里插入图片描述

下图就是index.jsp页面:(可以看到,我给要传递的那个参数命名为param,仅仅是随意起的名字,不必在意)
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43666859/article/details/84628235