views:

68

answers:

2

I am new to Spring MVC, need guidance

My jsp is like :

<form:form name="form1" method="post" action="input.htm?method=getHealth">
.......
<td >
<form:select path="envList">
<form:options items="${envList}"/>
</form:select>
</td>

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: 

I guess you should specify the name attribute of <form:select

Note that if you are not using the binding capabilities of spring (i.e. - spring auto-creating your command object based on request parameters), you can use the <select> tag (without any spring stuff)

Bozho
A: 

I was having a similar issue to this and I managed to fix it by catching the null early in my controller. Try this:

if(request.getParameter("form1") == null) { 
  return new ModelAndView();
}

Hope it helps.

Roddick