2016-06-16 20 views
-1

こんにちは私は1つのJSPから別の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

resultet.getInt(1)はあなたが期待しているように動作しないと思うので、この方法でより読みやすくなります。 – erolkaya84

+0

ありがとう:)私は試してみましょう@ erolkaya84 –

0

あなただけのEL(式言語)を使用してリダイレクトをJSPにJSPを使用している場合と

${param.empId}を置くには、あなたがこれを行うために必要<%=request.getParameter("empName") %>

<%=request.getParameter("empId") %>

${param.empName} instedのinstedあなたはJSPからJSPにリダイレクトしています。他には必要ありません。

関連する問題