Insert data from SQL server to struts2

0

Hello good night everyone, I explain my problem I'm making an insert to my table:

but this is what is stored in the bd:

The result I'm looking for is a lot of this:

I provide my entity class:

public class CoordenadasP {


String CordNort;
String CordSurr;

public CoordenadasP(String CordSurr, String CordNort ){


    this.CordNort=CordNort;
    this.CordSurr=CordSurr;
}


public CoordenadasP(){



}



public String getCordNort() {
    return CordNort;
}


public void setCordNort(String cordNort) {
    CordNort = cordNort;
}


public String getCordSurr() {
    return CordSurr;
}


public void setCordSurr(String cordSurr) {
    CordSurr = cordSurr;
}



}

my model:

public static  String addMoreDetails(List<CoordenadasP> cords) throws Exception
{  
    try
    {

        Connection con=Coneccion.getConnection();
        PreparedStatement ps=con.prepareStatement("insert into Coordenadass (CodN,CodS) values(?,?);");

     for(CoordenadasP cord : cords) {
         ps.setString(1, cord.getCordNort());
         ps.setString(2, cord.getCordSurr());

         ps.addBatch();
    }
    int counts[] = ps.executeBatch();
    if ( counts.length == cords.size() )
        return "someMEssage";
    else
        return null; 
   }
   catch(Exception ex)
   {
    return ex.toString();
   }
}

my action:

public class ActionCoordenadass extends ActionSupport{


private ArrayList <CoordenadasP>  cords;



public ArrayList<CoordenadasP> getCords() {
    return cords;
}



public void setCords(ArrayList<CoordenadasP> cords) {
    this.cords = cords;
}



public String inserCord() throws Exception{
    ModelCoordenaP ad = new ModelCoordenaP();
    ModelCoordenaP.addMoreDetails(cords);

    return SUCCESS;

}

and finally my jsp:

</head>
    <body>
<s:form role="form" action="inserCord" method="POST">
               <table>
<tr>
    <td width="10%">Reg X:</td>
    <td width="15%" >Reg Y :</td>

</tr>
  <tr>
     <td  width="30%" ><input  type="text" name="details.CordNort" /></td>

    <td  width="30%" ><input  type="text" name="details.CordSurr"  /></td>
  </tr>
  <tr>
    <td  width="30%"><input type="text" name="details.CordNort"  ></td>
  <td  width="30%"><input type="text" name="details.CordSurr"  ></td> 
  </tr>
<tr>
 <td  width="30%"><input type="text" name="details.CordNort"  ></td>
  <td  width="30%"><input type="text" name="details.CordSurr" ></td>
</tr>
</table>
              <div class="box-footer">
                <button type="submit" class="btn btn-primary">SAVE</button>
              </div> 
            </s:form>
     <s:form role="form" action="consulta" method="POST"> 
              <div class="box-footer">
                <button href="#" type="submit" class="btn btn-primary">RETURN!</button>
              </div>
      </s:form>

I do not know what I'm doing wrong, thank you in advance!

    
asked by DrGun Gun 26.10.2017 в 04:01
source

1 answer

0

In Struts2 you can use the <s:textfield label="Username" name="username" /> tag in the following way:

<s:textfield label="Coord X:" name="cords[0].cordNort"/>

Several things are wrong with your code. I suggest you start without the arrangement with a simple coordinate object and once that works you can learn to use the arrangements in struts.

By convention: the accessors in your action (get and set) are written in "lower Camel Case" getCords()[0].getCordNort() . When you use them in your JSP struts it automatically removes or sets the get (or the set ) and changes initial case and interprets them as: cords[0].cordNort

    
answered by 27.10.2017 в 16:10