当我在spring mvc应用程序中单击它时,我的提交按钮没有点击控制器
<div class="form-group">
<form action="searchInfo" method="GET">
<label class=" control-label col-sm-2">No</label>
<div class="col-sm-4"> <input class="form-control" type='text' name='searchName' id='searchName'/> </div>
<div class="col-sm-4"><input class="btn btn-success" type='submit' value='Validate'/></div>
</form>
</div>
这是控制器代码
@Autowired
private IndividualService infoService;
@RequestMapping("getAllInfo")
public ModelAndView getAllInfo() {
return new ModelAndView("sDescription");
}
@RequestMapping("searchInfo")
public ModelAndView searchInfo(@RequestParam("searchName") String searchName) {
logger.info("Searching the Individual Info: "+searchName);
List<InfoIndividual> infoList = infoService.getAllInfos(searchName);
return new ModelAndView("sDescription", "infoList", infoList);
}
这是应用程序描述符定义的web.xml代码
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>emInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>emInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<error-page>
<error-code>404</error-code>
<location>/Error.jsp</location>
</error-page>
<error-page>
<error-code>400</error-code>
<location>/Error.jsp</location>
</error-page>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
当我单击表单的子菜单按钮时,为什么我的spring应用程序没有按下控制器。调试了每一层,它仍然看起来相同
答案 0 :(得分:-1)
我认为这是因为提交按钮上的值attr并且您没有匹配的控制器方法。试着摆脱它。 变化
<div class="col-sm-4"><input class="btn btn-success" type='submit' **value='Validate'**/></div>
到
<div class="col-sm-4"><input class="btn btn-success" type='submit'/></div>