[英]send value from one jsp to another jsp using href
如何將resultset.getInt(1)
這個值發送到另一個jsp頁面,我正在嘗試這個但是沒有用。
<td><a href="result.jsp?Id="+<%=resultset.getInt(1)%> ><%= resultset.getInt(1) %></a></td>
result.jsp中
<%
String ss =request.getParameter("Id");
System.out.println("my value" + ss);
%>
我在result.jsp
得到了""
。
試試這個:
<td>
<a href=<%= "\"result.jsp?Id=" + resultset.getInt(1) + "\"" %> ><%= resultset.getInt(1) %></a>
</td>
我建議你看一下生成的HTML。 看起來第一個<%=resultset.getInt(1)%>
寫在href的值之外。 這可能會更好:
<td><a href="result.jsp?Id=<%=resultset.getInt(1)%>" ><%= resultset.getInt(1) %></a></td>
在旁注中我會說你看看表達式語言並使用它而不是在JSP中內聯java代碼。 很難調試和維護這樣的代碼。
這是我們的第一頁: -
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8" import="java.util.*;" %>
<!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>Insert title here</title>
</head>
<body>
<form action="xp.jsp" method="get">
<input type="text" value="" name="lol">
<input type="submit" value="submit"></input>
</form>
<a href="xp.jsp?lol=hahah">click me</a>
</body>
</html>
這是我們的xp.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>Insert title here</title>
</head>
<body>
<%=request.getParameter("lol") %>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.