javascript - How to transfer onclick with a jsp variable and direct to other page -


do know how transfer variable button other page. creating update , delete site. database query data, , there edit button, if press edit, direct second site. site show data information update.

source code below. used below source code, when enter edit, will not direct page(edit_delete.jsp) can 1 plem me, whay wrong code please see bold in source code mark, might problem.

-----------------------------------------source code-----------------------------------------------------------

<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, 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>");        }     %> 

always try avoid scriplet instead use javaserver pages standard tag library , expression language more easy use , less error prone.

sql tag library designed accessing databases quick prototyping , simple applications.

sample code:

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

you can try window open() method instead of form submit it's simple request , value passed query string in url.

for e.g.

<input type='button' name='edit' value='edit' onclick='window.open("edit_delete.jsp?id=${row.no}");'/> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -