嗨朋友我试图通过链接将值从一个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","root@123");
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 :(得分:0)
注意强>
要从以下答案运行代码,您必须包含JSTL
代码库。它可以找到here。
或者要包含,请在JSP顶部写下以下行。
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<强>答案强>
你可以试试吗?
<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>
答案 1 :(得分:0)
如果您使用jsp到jsp重定向,请使用EL(表达式语言)并输入
${param.empId}
<%=request.getParameter("empId") %>
${param.empName}
<%=request.getParameter("empName") %>
您需要这样做,因为您正在从JSP重定向到JSP,而不是必需的......