not able to hit spring controller

Multi tool use
Multi tool use


not able to hit spring controller



I have simple form action with spring below . Not able to hit the controller on click of submit . Whats wrong . I am using spring 4.3.17



index.jsp


<form action="/springold/ecSearch" method="get">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit">
</form>



web.xml


servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/springold/*</url-pattern>
</servlet-mapping>





dispatcher-servlet.xml :


<context:component-scan base-package="com"/>
<mvc:annotation-driven/>



Controller class :


package com;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class ECActivityController {


@RequestMapping(value="/ecSearch", method=RequestMethod.GET)
public void proccess(){
System.out.println("done");

}



}





try to use @RestController instead of @Controller
– dehasi
Jun 29 at 12:29


@RestController


@Controller





not working with @RestController as well . I have set the context root as springtest Please help
– Ashish Banker
Jun 29 at 12:56






Try changing <url-pattern>/springold/*</url-pattern> to <url-pattern>/*</url-pattern> and see if you can GET /springold/ecSearch. You shouldn't repeat your context path in the <url-pattern> value.
– Robert Hume
Jun 30 at 12:45


<url-pattern>/springold/*</url-pattern>


<url-pattern>/*</url-pattern>


/springold/ecSearch


<url-pattern>




1 Answer
1



I assume that url in form is correct and /springold is a root of context path.
But I see here other issue, the form is passes two params: lname and lname.
So your method of controller have to seems like that:


/springold


lname


lname


@RequestMapping(value = "/ecSearch", method = RequestMethod.GET)
public void proccess(@RequestParam("fname") String fname, @RequestParam("lname") String lname) {
System.out.println("done");
}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

uQbOBnSeSUkOV69,G9zQu1FGdanRurB,Zf2JfxZgB7wr,GAV1CwX9jrYkH,RWwmozum4wXV,k7GhPwjiRoQX
sNn k0KgYR3xPz0ZGkdrz jJxa9 68I8KK srlIa zT4KNKxIxrbnl6 i,6QpnkS0,yeC3VBmYa

Popular posts from this blog

Delphi Android file open failure with API 26

.

Amasya