开发者

Spring MVC Multiaction Controller getParameter returning null

开发者 https://www.devze.com 2023-01-20 05:56 出处:网络
I am new to Spring MVC, need guidance My jsp is like : <form:form name=\"form1\" method=\"post\" action=\"input.htm?method=getHealth\">

I am new to Spring MVC, need guidance

My jsp is like :

<form:form name="form1" method="post" action="input.htm?method=getHealth">
.......开发者_C百科
<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


You can use @RequestParam("envList") String envList if you are using Spring 3 or annotations

public ModelAndView getHealth(@RequestParam("envList") String envList
    , HttpServletRequest request, HttpServletResponse response) {
    .......................
}

Above implemetation helps you to get the required value directly from jsp .


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.


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消