2016-06-16 84 views
-1

您好朋友我想通過鏈接將值從一個jsp傳遞給另一個,但值不會通過。我在論壇中提到了很多答案。沒什麼幫助。將值從jsp傳遞給jsp時獲取空值

Display.jsp

<%@ page import="java.sql.*" %> 
<%ResultSet resultset =null;%> 

<HTML> 
<HEAD> 
    <TITLE>Select element drop down box</TITLE> 
</HEAD> 

<BODY> 



<h2>EMPLOYEE DETAILS</h2> 
<br> 
<form action = "Form.jsp"> 
<button type = "submit">Add New Employee</button> 
</form> 
<% 
    try{ 
      Class.forName("com.mysql.jdbc.Driver").newInstance(); 

      Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/hirarchy_check","root","[email protected]"); 

      Statement statement = connection.createStatement() ; 

      resultset =statement.executeQuery(" SELECT e.Emp_Id,e.Emp_Name ,e.Emp_Designation, m.Emp_Designation"+ 
        " FROM employee_details e " + 
        " INNER JOIN employee_details m on e.Manager_id = m.Emp_Id ") ; 

%> 
    <table border = 1> 
       <tr><th>Employee Id</th><th>Employee Name</th><th>Employee Designation</th><th>Reporting Manager</th><th>View</th></tr> 
       <tr><td>1</td><td>Steve</td><td>ceo</td><td>0</td><td><a href = 'FormUpdate.jsp'>View</a></td></tr> 

    <%  
       while(resultset.next()) 
       { %> 
        <tr><td><%=resultset.getInt(1)%></td><td><%=resultset.getString(2)%></td> 
        <td><%=resultset.getString(3)%></td><td><%=resultset.getString(4)%></td> 
        <td><a href="EmpDetails.jsp?empId=${resultset.getInt(1)}&empName=${resultset.getString(2)}" >update</a></td></tr> 
      <% } %> 

    </table> 

<%   } 
     catch(Exception e) 
     { 
      out.println(e); 
     } 
%> 

</BODY> 
</HTML> 

而且我必須通過值的頁面是

EmpDetails.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Employee Details</title> 
</head> 
<body> 
out.println<%=request.getParameter("empId") %> 
out.println<%=request.getParameter("empName") %> 
</body> 
</html> 

回答

0

注意

,從運行代碼在答案下面,您必須包含JSTL標籤庫。它可以發現here

或者要包含,請在JSP的頂部寫入以下行。

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> 

回答

能不能請你的forEach?

<c:forEach var="row" items="${resultset.rows}"> 
<tr> 
<td><a href="EmpDetails.jsp?empId=${row.Emp_Id}&empName=${row.Emp_Name}">update</a></td> 
</tr>  
</c:forEach> 
+0

m中是否有任何錯誤y代碼? @ erolkaya84 –

+0

我認爲resultset.getInt(1)不能像你期望的那樣工作,而且這種方式更具可讀性。 – erolkaya84

+0

謝謝:)我會試試@ erolkaya84 –

0

如果你正在使用JSP把jsp重定向只是使用EL(表達式語言),並把

${param.empId} insted的的<%=request.getParameter("empId") %>

${param.empName} insted的的<%=request.getParameter("empName") %>

你必須這樣做,因爲你正在從JSP重定向到JSP,否則不需要...