您好朋友我想通過鏈接將值從一個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>
m中是否有任何錯誤y代碼? @ erolkaya84 –
我認爲resultset.getInt(1)不能像你期望的那樣工作,而且這種方式更具可讀性。 – erolkaya84
謝謝:)我會試試@ erolkaya84 –