2016-08-14 45 views
-1

我有三個jsp頁面:annotation.jsp,check.jsp和end.jsp。我從check.jsp重定向到annotation.jsp或根據條件重定向到end.jsp。在重定向的同時,我也傳遞了一個變量。在重定向jsp頁面時傳遞變量

Annotation.jsp:

<%@page language="java"%> 
<%@ page import="java.io.*" %> 
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>Annotation Page</title> 
</head> 
<body> 
    <% 
      String user = request.getParameter("user"); 
    %> 
    <form method="get" action="check.jsp"> 
     <input type="hidden" name="user" value="<%=user%>"> 
     <input type="radio" name="similarity" value="Similar"> Similar<br> 
     <input type="radio" name="similarity" value="Dissimilar"> Dissimilar<br> 
     <input type="submit" name="submit" value="Submit"> 
    </form> 
</body> 
</html> 

Check.jsp:

<%@page import="java.io.*"%> 
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>JSP Page</title> 
</head> 
<body> 
    <form method="get"> 
     <% 
        String user = request.getParameter("user"); 
        if (condition) { 
         String redirectURL1 = "annotation.jsp"; 
         response.sendRedirect(redirectURL1); 
        } else { 
         String redirectURL2 = "end.jsp"; 
         response.sendRedirect(redirectURL2); 
        } 
     %> 
    <input type="hidden" name="user" value="<%=user%>"> 
    </form> 
</body> 
</html> 

我想知道這個變量是否通過與否與此類型的重定向?因爲我在來自check.jsp的annotation.jsp中獲取了null值。

回答

0

將行:

String redirectURL1 = "annotation.jsp; 
response.sendRedirect(redirectURL1); 

有:

String redirectURL1 = "annotation.jsp?User="+request.getParameter("User"); 
response.sendRedirect(redirectURL1);