简体   繁体   English

使用href从一个jsp发送值到另一个jsp

[英]send value from one jsp to another jsp using href

How to send resultset.getInt(1) this value to another jsp page ,I am trying this but not working. 如何将resultset.getInt(1)这个值发送到另一个jsp页面,我正在尝试这个但是没有用。

<td><a href="result.jsp?Id="+<%=resultset.getInt(1)%> ><%= resultset.getInt(1) %></a></td>

result.jsp result.jsp中

<% 
String ss =request.getParameter("Id");
System.out.println("my value" + ss);
%>

I m getting "" in result.jsp . 我在result.jsp得到了""

Try this: 试试这个:

<td>
    <a href=<%= "\"result.jsp?Id=" + resultset.getInt(1) + "\"" %> ><%= resultset.getInt(1) %></a>
</td>

I suggest you take a look at the generated HTML. 我建议你看一下生成的HTML。 It looks like the result of the first <%=resultset.getInt(1)%> is written outside the value of the href. 看起来第一个<%=resultset.getInt(1)%>写在href的值之外。 This might work better: 这可能会更好:

<td><a href="result.jsp?Id=<%=resultset.getInt(1)%>" ><%= resultset.getInt(1) %></a></td>

On a side note I would sugest you take a look at expression language and use that instead of inlining java code in your JSP. 在旁注中我会说你看看表达式语言并使用它而不是在JSP中内联java代码。 It is hard to debug and maintain such code. 很难调试和维护这样的代码。

this is our first page :- 这是我们的第一页: -

    <%@ 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>

and this our xp.jsp:- 这是我们的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM