/*form created*/ /jsp code for creating dropdownlist using struts2/ /java action class for adding form elements and accessing values/ //struts.xml file for controllingI tried to create a dropdown list using struts2.it is not working.can you find the errors in this code?
<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>
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>
<package name="b" extends="struts-default">
<action name="addemp" class="b.EmpAdd" >
<result name="success">addemp.jsp</result>
</action>
</package>
</struts>
Questions by Category