views:

28

answers:

2

I am new to Spring MVC, need guidance

My jsp is like : .......

<form:select path="envList">
<form:options items="${envList}"/>

My .java is like:

public class InputController extends MultiActionController{ 
  public ModelAndView getHealth(HttpServletRequest request,HttpServletResponse response) {   
    ....................... 
    String selectedEnv =request.getParameter("envList"); 
  }
}

Here I want to catch selected value from the dropdown to java,but request.getParameter("envList") is returning null. Please suggest how can I get selected value from jsp to .java.

Thanks in advance

A: 
  1. Make sure that you are wrapping the select control in a Spring form.
  2. The path attribute of your select control the name of the property that will contain the currently selected element in the combo box in the command object (value of the commandName attribute) of the spring form. This will be updated when the form is submitted.

Below is a partial example. Remember that you must add an object to the Model with the name referenced by the commandName attribute of the form (in thix example: "ModelObjectNameHere").


<sf:form commandName="ModelObjectNameHere">

dwb
A: 

how to map <form:select> in Spring form ? so that I can catch the selected value

Ankita