Struts <html:select> drop down box example

Download this Struts select option (drop down box) example –

In this Struts example, you will learn how to create a HTML select option (drop down box) with Struts <html:select> and <html:option> tag. The <select> tag is used to create a select list (drop-down list); while <option> tags inside the select element define the available options in the list.

1. Folder Structure

This is the final project structure created by Maven. Please create the corresponding folders.


2. Action class

Create an Action class, do nothing but forward the request.

package com.mkyong.common.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.mkyong.common.form.HtmlSelectOptionForm;
public class HtmlSelectOptionAction extends Action{
	public ActionForward execute(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response) 
        throws Exception {
	  HtmlSelectOptionForm htmlSelectOptionForm = (HtmlSelectOptionForm)form;
	  return mapping.findForward("success");

3. Properties file

Create a properties file, and declare the error and label messages.

#error message = Please select a year.
#label message = Select a year = Submit = Reset

4. ActionForm

Create a ActionForm, contains a year variable to hold the select option value.

package com.mkyong.common.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
public class HtmlSelectOptionForm extends ActionForm{
	String year;
	public String getYear() {
		return year;
	public void setYear(String year) {
		this.year = year;
	public ActionErrors validate(ActionMapping mapping,
	  HttpServletRequest request) {
	    ActionErrors errors = new ActionErrors();
	    if( getYear() == null || ("".equals(getYear())))
	    	 new ActionMessage(""));
	    return errors;
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		// reset properties
		year = "";

5. JSP Page

Use the Struts’s HTML tag <html:select> and <html:option> to create a HTML drop down list.


<%@taglib uri="" prefix="html"%>
<%@taglib uri="" prefix="bean"%>
<h1>Struts html:select example</h1>
<html:form action="/Select">
<html:messages id="err_name" property="">
<div style="color:red">
	<bean:write name="err_name" />
<div style="padding:16px">
<bean:message key="" /> :
<html:select property="year">
    <html:option value="">-- None --</html:option>
	<html:option value="1980">1980</html:option>
	<html:option value="1981">1981</html:option>
	<html:option value="1982">1982</html:option>
	<html:option value="1983">1983</html:option>
	<html:option value="1984">1984</html:option>
	<html:option value="1985">1985</html:option>
<div style="padding:16px">
	<div style="float:left;padding-right:8px;">
                   <bean:message key="" />
           <bean:message key="" />

Get the selected drop down box value from htmlSelectOptionForm form and display it


<%@taglib uri="" prefix="bean"%>
	Your selected year is : 
	<bean:write name="htmlSelectOptionForm" property="year" />

6. struts-config.xml

Create a Struts configuration file and link all together.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 
			<forward name="success" path="/pages/display.jsp"/>
		parameter="" />

7. web.xml

Final step, create a web.xml and integrate the Struts framework.

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >
  <display-name>Maven Struts Examples</display-name>

Access it



Select a year and pressed the submit button, it will forward to


and display the selected drop down box value.

Tags :

About the Author

Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.


  • Pingback: d grade electrician()

  • Pingback: house blue()

  • Pingback: zak?ad szklarski piotrk√≥w trybunalski()

  • Pingback: pay day loans()

  • Pingback: 1 plumber dave miller()

  • Pingback: emergency locksmith lubbock tx()

  • Pingback: locksmith o'fallon illinois()

  • Pingback: helpful resources()

  • Pingback: electrician 2015 salary()

  • Pingback: paypal loans()

  • Pingback: My site()

  • Pingback: site()

  • Pingback: my response()

  • Pingback: concrete()

  • Pingback: water ionizer loan()

  • Pingback: alkaline water()

  • Pingback: water ionizer()

  • Pingback: laan penge online()

  • Pingback: car parking()

  • Pingback: lan penge()

  • Pingback: parking()

  • Pingback: xnxx()

  • Pingback:

  • Pingback: DIRECTV vs Dish()

  • Pingback: Chinese ava devine ass-fucked deeply()

  • Pingback: streaming movies()

  • Pingback: stream movies()

  • Pingback: Blue Coaster33()

  • Pingback: Homepage()

  • goods

    I am only commenting to let you know what a outstanding encounter my friend’s child encountered reading yuor web blog. She learned some things, which included what it’s like to have a very effective teaching nature to get many people without hassle have an understanding of selected tortuous matters. You undoubtedly exceeded our expectations. Many thanks for coming up with these good, safe, informative as well as easy guidance on the topic to Tanya.

  • sankar

    in struts 1.3.10 ,i want to display value in dropdrop list from database.

    DAO class return a list object , how to display arraylist object in jsp.

    Action class: masterList = UploadDAO.getValues(“list”);
    request.setAttribute(“masterlist”, masterList);

    Dao Class : Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
    conn = ConnectionManager.getConnection();
    UploadVO uVO = null;
    logger.debug(“in DAO query is ” + SQLQueries.GET_POLICY_MASTER);
    stmt = conn.prepareStatement(SQLQueries.GET_POLICY_MASTER);
    masterList = new ArrayList();
    rs = stmt.executeQuery();
    while (
    uVO = new UploadVO();
    logger.debug(“added do ” + uVO);
    } catch (Exception exp) {
    logger.error(“Exception is ” + exp.getMessage());

    } finally {

    try {
    } catch (Exception exp1) {

    return masterList;

    in Jsp page i got an error null pointer exception,

    please send me dropdown list sample code in jsp get the values from db.

  • chinkun

    in the above drop-down-box-example you hard-code the value.But i want to brought it from database not hard-code.can you kindly give me the code?

    • sankar

      please help me how to set the values in dropdown list from database , with in jsp page how to get the array list values in dropdown list ?

  • Pingback: Struts <html:select> drop down box example | Struts - html()