Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Struts I tried to create a dropdown list using struts2.it is not working.can you find the errors in this code?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


rony rony
I tried to create a dropdown list using struts2.it is not working.can you find the errors in this code?
0 Answer(s)      2 years and 11 months ago
Posted in : Struts


/jsp code for creating dropdownlist using struts2/

<html>
<body>
<p:form action="addemp" method="post">/*form created*/
<p:select name="designation" label="Enter Designation " list="design" /> /*dropdown list included*/
<p:submit name="submit"/>//submit
</p:form>
</body>
</html>

/java action class for adding form elements and accessing values/

import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.*;
import com.opensymphony.xwork2.ActionSupport;
import java.sql.SQLException;
import java.util.ArrayList;

public class EmpAdd extends ActionSupport {

public List<String> design;//list to be dropped
String designation;//the selected string to be taken

public List<String> getDesign() {//getter method of list
    return design;
}

public void setDesign(List<String> design) {/*setter method of list*/
    this.design = design;
}

public String getDesignation() {
    return designation;
}

public void setDesignation(String designation) {
    this.designation = designation;
}

public String execute() throws Exception{


            design = new ArrayList<String>();  //creating the list      
            design.add("es");//adding to the list
            design.add("as");
            return SUCCESS;
}
}

//struts.xml file for controlling

<struts>
<package name="b" extends="struts-default">
<action name="addemp" class="b.EmpAdd" >
<result name="success">addemp.jsp</result>
</action>
</package>
</struts>

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com