如何使用jsp变量传输onclick并直接到其他页面
How to transfer onclick with a jsp variable and direct to other page
有人知道如何将变量从按钮转移到其他页面吗?我正在创建一个更新和删除网站。数据库查询所有的数据,并有一个编辑按钮,如果我按编辑,它将直接到第二个站点。本网站将显示您需要更新的数据信息。
源代码如下。我使用下面的源代码,当我进入编辑,将不会直接到页面(edit_delete.jsp)谁能告诉我,代码有什么问题吗请查看我标记的源代码中的粗体,这可能是一个问题。
----------------------------------------- 源代码 -----------------------------------------------------------
<script language="javascript">
function editRecord(no){
var f=document.form1;
alert(no);
f.method="post";
**f.action='edit_delete.jsp?id='+no;**
f.submit();
}
</script>
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/webapp?user=root&useUnicode=true&characterEncoding=big5");
stmt=con.prepareStatement("select id, no, name, class, from test");
rs = stmt.executeQuery();
while(rs.next()) {
int test = rs.getInt("no");
out.print("<tr><td>");
out.print(rs.getString("id"));
out.print("</td><td>");
out.print(rs.getString("no"));
out.print("</td><td>");
out.print(rs.getString("name"));
out.print("</td><td>");
out.print(rs.getString("class"));
out.print("</td><td>");
out.print("</td><td>");
**out.println("<input type='button' name='edit' value='Edit' onclick='editRecord('rs.getInt('no'))'>");**
out.print("</td></tr>");
}
%>
始终尽量避免使用 script ,而是使用更容易使用且更不容易出错的JavaServer Pages标准标记库和表达式语言。
SQL标签库是为快速原型和简单应用程序访问数据库而设计的。
示例代码:
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
...
<sql:setDataSource var="webappDataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/webapp?user=root&useUnicode=true&characterEncoding=big5"
user="root" password="" />
<sql:query dataSource="${webappDataSource}"
sql="select id, no, name, class, from test" var="result" />
<table width="100%" border="1">
<c:forEach var="row" items="${result.rows}">
<tr>
<td>${row.no}</td>
<td>${row.id}</td>
<td>${row.no}</td>
<td>${row.name}</td>
<td>${row.class}</td>
<td><input type='button' name='edit' value='Edit' onclick='editRecord(${row.no})' /></td>
</tr>
</c:forEach>
</table>
你可以尝试使用Window open()方法代替表单提交,因为它是简单的get请求和值在URL中作为查询字符串传递。
例如<input type='button' name='edit' value='Edit' onclick='window.open("edit_delete.jsp?id=${row.no}");'/>
相关文章:
- 使用JSP从服务器检索和显示图像
- 将jsp文件下拉列表中的选定项分配给一个java变量(比如String selection)
- 如何添加浮动和非浮动,其他
- 与其他库的jQuery.noConflict()
- 播放当前视频时如何停止其他视频?JavaScript
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- 制作一个不带HTML a标记但在动画播放完毕后指向其他页面的超链接
- 在jsp中,隐藏一个基于其他具有日期选择器的字段的字段
- 在其他元素的基础上隐藏/取消隐藏jsp元素
- 如何从其他 jsp 调用方法/函数以包含在另一个 jsp 的 jstree 中
- 如何在jsp中插入单选按钮、复选框和其他输入类型
- 如果用户在jsp中填写一个字段(同时使用springmvc和hibernate),我如何自动填写其他表单字段
- 如何将给定的文本链接到其他JSP页面
- JSP会话丢失后,javascript窗口替换位置与其他JSP页面
- Liferay portlet:从javascript重定向到其他jsp页面
- 如何显示文本以及JQuery进度条,并在完成后转发到其他JSP页面
- 要更改默认文本"No File Selected"在JSP中添加一些其他文本的浏览器按钮
- 重定向其他Jsp JavaScript
- 如何使用jsp变量传输onclick并直接到其他页面
- 使用javascript向位于JSP中其他域的Servlet发送请求参数