Share on Google+Share on Google+

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)      5 years and 2 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>

Ads

View Answers









Related Tutorials/Questions & Answers:
Advertisements
Tutorials   
Java Spring Hibernate Struts Training Dynamic tabs in struts 1.2 Unable to upload a file to mysql database using struts1 Pagination in struts 2 struts2 filterdispatcher is deprecated please use the new filters viewing How to add struts2 dependency in Maven? Struts Exception Handling can you check below code if any erors multimedia how to display the value of termcell name in label class not found exception Where to learn Struts 2? dropdown cacheing Upload and Download Large files in jsp What is Struts 2 framework struts and hibernate based health care project source code struts and hibernate based health care project source code Struts 2 Integration with Struts 1 About captcha of strut2 About captcha of strut2 Which is the good website for struts 2 tutorials? advance java source code source code In Struts 2 how to pass the Struts struts internationalization for Korean language struts2 Struts2 and Hibernate Fetch Data Base Value Struts2 and Hibernate Fetch Data Base Value Struts2 and Hibernate i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse Struts2 and Hibernate Struts2 and Hibernate Struts2 validation Procedure Struts2 validation Procedure Struts2 validation Procedure Struts2 validation Procedure Struts 2 action-validation.xml not loading Struts-2 and Ajax integration STRUTS QUESTION conerting web project into .exe file About Select tag ScartApplication aplicacion ecommerce struts 1.3 struts 1.3 sms prob Need to know struts1 all jar file names struts with hibernate

Ads

 
Advertisement null

Ads