html - How to get value of generated row value for another action when generated submit button is clicked -


i want know how dynamically generated table row value (eg. empp_id) when clicking submit button generated each row dynamically.

below code. used generate each row , submit button each row. don't know how use submit button , pass value of 'id' column action.

struts.xml

<?xml version="1.0" encoding="utf-8"?> <!doctype struts public "-//apache software foundation//dtd struts configuration 2.3//en"  "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>     <constant name="struts.enable.dynamicmethodinvocation" value="false" />     <constant name="struts.devmode" value="false" />      <package name="default" namespace="/" extends="struts-default">           <action name="edit" class="com.ojt.database.edituseraction" method="execute">             <result name="success">edituser.jsp</result>             <result name="error"></result>         </action>  </struts> 

edituseraction.java

package com.ojt.database;  import java.sql.connection; import java.sql.drivermanager; import java.sql.preparedstatement; import java.sql.resultset; import java.util.arraylist; import java.util.list;  import com.opensymphony.xwork2.actionsupport;  @suppresswarnings("serial") public class edituseraction extends actionsupport {     list<user> liuser=null;       public list<user> getliuser() {         return liuser;     }       public void setliuser(list<user> liuser) {         this.liuser = liuser;     }       @override     public string execute() throws exception {         connection conn;         string ret = "error";         try {              string url = "jdbc:mysql://localhost:3306/test";             class.forname("com.mysql.jdbc.driver");             conn = drivermanager.getconnection(url, "root", "root");             string sql = "select * user";             preparedstatement ps = conn.preparestatement(sql);             resultset rs = ps.executequery();             liuser=new arraylist<user>();             while (rs.next()) {                 user user = new user();                 user.setid(rs.getint(1));                 user.setname(rs.getstring(2));                 user.setpassword(rs.getstring(3));                 liuser.add(user);                }             conn.close();             ret = "success";             system.out.println(ret);         } catch (exception e) {             e.printstacktrace();             ret = "error";             system.out.println(ret);         }         return ret;     }  } 

edituser.jsp

<%@ page language="java" contenttype="text/html; charset=iso-8859-1"     pageencoding="iso-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="display" uri="http://displaytag.sf.net/el"%> <!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>edit</title> </head> <body>     <table cellpadding="20" align="center">         <tr>             <th>id</th>             <th>name</th>             <th>password</th>          </tr>          <s:iterator value="liuser">             <tr>                 <td><s:property value="id" /></td>                  <td><s:property value="name" /></td>                 <td><s:property value="password" /></td>                 <td><s:submit value="edit" theme="simple" action="review" method="post"/></td>             </tr>         </s:iterator>     </table>  </body> </html> 

i need please. can't go further, stuck here.

  1. when use <s:property/>, not creating form tag, simple text.
    to send printed <s:property/>, use <s:hidden/> in conjunction it.

  2. to send list of object jsp, need use iteratorstatus object specify index.

  3. you not using form. need form post in standard, non-ajax way.

  4. you need 2 action's methods, or 2 actions: 1 display data, other edit it.
    in execute() method initializing list every time:
    liuser=new arraylist<user>();,
    so 1 coming page lost.

you in deep water. suggest stop moment , take closer @ html, http, struts2 , tags, otherwise frustrated quite soon.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -