<a> tag in html
<a> tag in html
我在JSP文件中有以下代码:
rs=stmt.executeQuery("select * from routemaster");
if(rs!=null){
%>
<table class="notebook" align="center">
<tr class=row_title>
<th class=row_title>RouteID</th>
<th class=row_title>RouteCode</th>
<th class=row_title>BusNo</th>
<th class=row_title>InBoundTime</th>
<th class=row_title>OutBoundtime</th>
<th class=row_title>Location</th></tr>
<%
while(rs.next()){
RouteID=rs.getString(1);
RouteCode=rs.getString(2);
InBoundtime=rs.getString(4);
OutBoundtime=rs.getString(5);
BusNo=rs.getString(6);
Location=rs.getString(7);
DisRow++;
%><tr class= <%=(DisRow%2!=0)? "row_even" : "row_odd"%>>
<td><%=RouteID%></td>
<td><a onclick="sendInfo('<%=RouteCode%>') " ><%=RouteCode%></a></td>
<td><%=BusNo%></td>
<td><%=InBoundtime%></td>
<td><%=OutBoundtime%></td>
<td><%=Location%></td>
</tr><%
}
%></table><%
}
和下面的JS代码:
sendInfo(txt){
var txt = window.opener.document.addbus0.RouteCode;
txt.value = txtVal;
window.close();
}
每当单击带有RouteCode
的链接时,都需要关闭窗口,并将选定的RouteCode
存储在会话中。我怎样才能做到这一点?
为此,您需要将值从客户端发送到服务器。实现此目的的正常方法是让客户端单击链接或将表单提交到服务器端的 URL,并将值作为 URL 中的请求参数或表单中的隐藏输入发送。
由于您使用的是链接,因此下面是一个带有链接的示例:
<a href="sendInfo.jsp?routeCode=<%=routeCode%>"><%=routeCode%></a>
然后在sendInfo.jsp
只是做
<%
String routeCode = request.getParameter("routeCode");
session.setAttribute("routeCode", routeCode);
%>
<script>
window.opener.document.addbus0.RouteCode.value = '<%=routeCode%>';
window.close();
</script>
与具体问题无关,这种代码风格不是最佳实践。Java 代码属于 Java 类,而不是 JSP 文件。JSP 文件应该只包含 HTML、JSP 标记和 EL。参见 如何避免 JSP 文件中的 Java 代码?此外,Java 编码约定要求变量名称应以小写开头。仔细阅读它们。你还有很长的路要走,祝你好运。
相关文章:
- lightbox in html 5 and javascript
- Hidding TextBox in html
- android spinner in html/javascript
- 如何从 javascript in html 访问 Java 中的方法
- Traversal in html dom with jquery
- Displaying php results in html <div>?
- Indy TIdHTTPServer OnCommandGet javascript in html not execu
- javascript var into onClick in html
- JavaScript in HTML head, innerhtml 不起作用
- Mustache using Partial Command in HTML & jQuery
- J'avaScript not in HTML
- How to keep the values on a registration form in html &
- jquery in html injection
- javascript onclick in html confusion
- Javascript conflict in Html & CSS
- textbox in html
- z-index and onclick in HTML
- javascript in html
- <a> tag in html
- lnk with database with ajax in html