No mapping for GET / in SpringMVC
up vote
1
down vote
favorite
I am trying to build Spring MVC web app.
The problem is in my welcome-page (localhost:8080/). In my output log I am seeing:
No mapping for GET /
I set my welcome page to URL: "/spring-mvc-login" but everytime I restart app it is trying to look for URL "/" which is not serve in my controller. I want to redirect welcome page to URL "/spring-mvc-login" but it doesnt work.
Funny thing is that when I type "localhost:8080/spring-mvc-login" it is working fine. The only problem is to redirect this URL to welcome-page.
WEB.XML
<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/todo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/spring-mvc-login</welcome-file>
</welcome-file-list>
todo-servlet.xml
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
And Controller
public class LoginController {
@RequestMapping(value = "/spring-mvc-login", method= RequestMethod.GET)
public String sayHello(){
return "login";
}
@RequestMapping(value = "/spring-mvc-login", method = RequestMethod.POST)
public String handleLoginRequest(@RequestParam String name, @RequestParam String password,
ModelMap modelMap){
modelMap.put("name",name);
modelMap.put("password", password);
return "welcome";
}
}
In Controller when i change @RequestMapping from "/spring-mvc-login "to "/" it is working fine of course but I want to redirect my welcome page to "/spring-mvc-login" not to "/". Thanks for help.
java spring spring-mvc dispatcher
add a comment |
up vote
1
down vote
favorite
I am trying to build Spring MVC web app.
The problem is in my welcome-page (localhost:8080/). In my output log I am seeing:
No mapping for GET /
I set my welcome page to URL: "/spring-mvc-login" but everytime I restart app it is trying to look for URL "/" which is not serve in my controller. I want to redirect welcome page to URL "/spring-mvc-login" but it doesnt work.
Funny thing is that when I type "localhost:8080/spring-mvc-login" it is working fine. The only problem is to redirect this URL to welcome-page.
WEB.XML
<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/todo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/spring-mvc-login</welcome-file>
</welcome-file-list>
todo-servlet.xml
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
And Controller
public class LoginController {
@RequestMapping(value = "/spring-mvc-login", method= RequestMethod.GET)
public String sayHello(){
return "login";
}
@RequestMapping(value = "/spring-mvc-login", method = RequestMethod.POST)
public String handleLoginRequest(@RequestParam String name, @RequestParam String password,
ModelMap modelMap){
modelMap.put("name",name);
modelMap.put("password", password);
return "welcome";
}
}
In Controller when i change @RequestMapping from "/spring-mvc-login "to "/" it is working fine of course but I want to redirect my welcome page to "/spring-mvc-login" not to "/". Thanks for help.
java spring spring-mvc dispatcher
I tried this and it didnt work.
– Rocky3582
Nov 21 at 18:45
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am trying to build Spring MVC web app.
The problem is in my welcome-page (localhost:8080/). In my output log I am seeing:
No mapping for GET /
I set my welcome page to URL: "/spring-mvc-login" but everytime I restart app it is trying to look for URL "/" which is not serve in my controller. I want to redirect welcome page to URL "/spring-mvc-login" but it doesnt work.
Funny thing is that when I type "localhost:8080/spring-mvc-login" it is working fine. The only problem is to redirect this URL to welcome-page.
WEB.XML
<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/todo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/spring-mvc-login</welcome-file>
</welcome-file-list>
todo-servlet.xml
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
And Controller
public class LoginController {
@RequestMapping(value = "/spring-mvc-login", method= RequestMethod.GET)
public String sayHello(){
return "login";
}
@RequestMapping(value = "/spring-mvc-login", method = RequestMethod.POST)
public String handleLoginRequest(@RequestParam String name, @RequestParam String password,
ModelMap modelMap){
modelMap.put("name",name);
modelMap.put("password", password);
return "welcome";
}
}
In Controller when i change @RequestMapping from "/spring-mvc-login "to "/" it is working fine of course but I want to redirect my welcome page to "/spring-mvc-login" not to "/". Thanks for help.
java spring spring-mvc dispatcher
I am trying to build Spring MVC web app.
The problem is in my welcome-page (localhost:8080/). In my output log I am seeing:
No mapping for GET /
I set my welcome page to URL: "/spring-mvc-login" but everytime I restart app it is trying to look for URL "/" which is not serve in my controller. I want to redirect welcome page to URL "/spring-mvc-login" but it doesnt work.
Funny thing is that when I type "localhost:8080/spring-mvc-login" it is working fine. The only problem is to redirect this URL to welcome-page.
WEB.XML
<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/todo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/spring-mvc-login</welcome-file>
</welcome-file-list>
todo-servlet.xml
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
And Controller
public class LoginController {
@RequestMapping(value = "/spring-mvc-login", method= RequestMethod.GET)
public String sayHello(){
return "login";
}
@RequestMapping(value = "/spring-mvc-login", method = RequestMethod.POST)
public String handleLoginRequest(@RequestParam String name, @RequestParam String password,
ModelMap modelMap){
modelMap.put("name",name);
modelMap.put("password", password);
return "welcome";
}
}
In Controller when i change @RequestMapping from "/spring-mvc-login "to "/" it is working fine of course but I want to redirect my welcome page to "/spring-mvc-login" not to "/". Thanks for help.
java spring spring-mvc dispatcher
java spring spring-mvc dispatcher
asked Nov 21 at 18:28
Rocky3582
4617
4617
I tried this and it didnt work.
– Rocky3582
Nov 21 at 18:45
add a comment |
I tried this and it didnt work.
– Rocky3582
Nov 21 at 18:45
I tried this and it didnt work.
– Rocky3582
Nov 21 at 18:45
I tried this and it didnt work.
– Rocky3582
Nov 21 at 18:45
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
Don't forget to use @RestController annotation.
If you want to redirect use:
@RequestMapping(value = "/", method = RequestMethod.GET)
public void redirect(HttpServletResponse httpResponse) throws Exception {
httpResponse.sendRedirect("/spring-mvc-login");
}
I am using @Controller annotation. When i add this it's working but is it the proper way to set welcome page?
– Rocky3582
Nov 21 at 18:48
I would use spring-boot-security package to set it all up. There you can have / landing page and set redirect if someone not authenticated. You can set context to /spring-mvc-login, but that would be weird.
– Denis Kovzelyuk
Nov 21 at 18:57
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 at 19:04
add a comment |
up vote
0
down vote
Try to remove "/"
before
<welcome-file>/spring-mvc-login</welcome-file>
after
<welcome-file>spring-mvc-login</welcome-file>
I have the same error "No mapping for GET /" so no change
– Rocky3582
Nov 21 at 18:44
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 at 18:51
I didnt serve URL "/", because I thought that I can redirect welcome page in my WEB.xml to adress "/spring-mvc-login"
– Rocky3582
Nov 21 at 18:55
of course when I add this @RequestMapping("/") annotation it is working fine. But how can I redirect my welcome page to adress "/spring-mvc-login" in WEB.xml? Is this can be done only in Controller Class?
– Rocky3582
Nov 21 at 18:59
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 at 19:09
add a comment |
up vote
0
down vote
Try to change web.xml content:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Or change controller mapping to:
@RequestMapping(value={"/", "/spring-mvc-login"})
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Don't forget to use @RestController annotation.
If you want to redirect use:
@RequestMapping(value = "/", method = RequestMethod.GET)
public void redirect(HttpServletResponse httpResponse) throws Exception {
httpResponse.sendRedirect("/spring-mvc-login");
}
I am using @Controller annotation. When i add this it's working but is it the proper way to set welcome page?
– Rocky3582
Nov 21 at 18:48
I would use spring-boot-security package to set it all up. There you can have / landing page and set redirect if someone not authenticated. You can set context to /spring-mvc-login, but that would be weird.
– Denis Kovzelyuk
Nov 21 at 18:57
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 at 19:04
add a comment |
up vote
0
down vote
Don't forget to use @RestController annotation.
If you want to redirect use:
@RequestMapping(value = "/", method = RequestMethod.GET)
public void redirect(HttpServletResponse httpResponse) throws Exception {
httpResponse.sendRedirect("/spring-mvc-login");
}
I am using @Controller annotation. When i add this it's working but is it the proper way to set welcome page?
– Rocky3582
Nov 21 at 18:48
I would use spring-boot-security package to set it all up. There you can have / landing page and set redirect if someone not authenticated. You can set context to /spring-mvc-login, but that would be weird.
– Denis Kovzelyuk
Nov 21 at 18:57
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 at 19:04
add a comment |
up vote
0
down vote
up vote
0
down vote
Don't forget to use @RestController annotation.
If you want to redirect use:
@RequestMapping(value = "/", method = RequestMethod.GET)
public void redirect(HttpServletResponse httpResponse) throws Exception {
httpResponse.sendRedirect("/spring-mvc-login");
}
Don't forget to use @RestController annotation.
If you want to redirect use:
@RequestMapping(value = "/", method = RequestMethod.GET)
public void redirect(HttpServletResponse httpResponse) throws Exception {
httpResponse.sendRedirect("/spring-mvc-login");
}
answered Nov 21 at 18:42
Denis Kovzelyuk
696
696
I am using @Controller annotation. When i add this it's working but is it the proper way to set welcome page?
– Rocky3582
Nov 21 at 18:48
I would use spring-boot-security package to set it all up. There you can have / landing page and set redirect if someone not authenticated. You can set context to /spring-mvc-login, but that would be weird.
– Denis Kovzelyuk
Nov 21 at 18:57
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 at 19:04
add a comment |
I am using @Controller annotation. When i add this it's working but is it the proper way to set welcome page?
– Rocky3582
Nov 21 at 18:48
I would use spring-boot-security package to set it all up. There you can have / landing page and set redirect if someone not authenticated. You can set context to /spring-mvc-login, but that would be weird.
– Denis Kovzelyuk
Nov 21 at 18:57
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 at 19:04
I am using @Controller annotation. When i add this it's working but is it the proper way to set welcome page?
– Rocky3582
Nov 21 at 18:48
I am using @Controller annotation. When i add this it's working but is it the proper way to set welcome page?
– Rocky3582
Nov 21 at 18:48
I would use spring-boot-security package to set it all up. There you can have / landing page and set redirect if someone not authenticated. You can set context to /spring-mvc-login, but that would be weird.
– Denis Kovzelyuk
Nov 21 at 18:57
I would use spring-boot-security package to set it all up. There you can have / landing page and set redirect if someone not authenticated. You can set context to /spring-mvc-login, but that would be weird.
– Denis Kovzelyuk
Nov 21 at 18:57
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 at 19:04
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 at 19:04
add a comment |
up vote
0
down vote
Try to remove "/"
before
<welcome-file>/spring-mvc-login</welcome-file>
after
<welcome-file>spring-mvc-login</welcome-file>
I have the same error "No mapping for GET /" so no change
– Rocky3582
Nov 21 at 18:44
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 at 18:51
I didnt serve URL "/", because I thought that I can redirect welcome page in my WEB.xml to adress "/spring-mvc-login"
– Rocky3582
Nov 21 at 18:55
of course when I add this @RequestMapping("/") annotation it is working fine. But how can I redirect my welcome page to adress "/spring-mvc-login" in WEB.xml? Is this can be done only in Controller Class?
– Rocky3582
Nov 21 at 18:59
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 at 19:09
add a comment |
up vote
0
down vote
Try to remove "/"
before
<welcome-file>/spring-mvc-login</welcome-file>
after
<welcome-file>spring-mvc-login</welcome-file>
I have the same error "No mapping for GET /" so no change
– Rocky3582
Nov 21 at 18:44
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 at 18:51
I didnt serve URL "/", because I thought that I can redirect welcome page in my WEB.xml to adress "/spring-mvc-login"
– Rocky3582
Nov 21 at 18:55
of course when I add this @RequestMapping("/") annotation it is working fine. But how can I redirect my welcome page to adress "/spring-mvc-login" in WEB.xml? Is this can be done only in Controller Class?
– Rocky3582
Nov 21 at 18:59
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 at 19:09
add a comment |
up vote
0
down vote
up vote
0
down vote
Try to remove "/"
before
<welcome-file>/spring-mvc-login</welcome-file>
after
<welcome-file>spring-mvc-login</welcome-file>
Try to remove "/"
before
<welcome-file>/spring-mvc-login</welcome-file>
after
<welcome-file>spring-mvc-login</welcome-file>
answered Nov 21 at 18:43
Jose
444
444
I have the same error "No mapping for GET /" so no change
– Rocky3582
Nov 21 at 18:44
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 at 18:51
I didnt serve URL "/", because I thought that I can redirect welcome page in my WEB.xml to adress "/spring-mvc-login"
– Rocky3582
Nov 21 at 18:55
of course when I add this @RequestMapping("/") annotation it is working fine. But how can I redirect my welcome page to adress "/spring-mvc-login" in WEB.xml? Is this can be done only in Controller Class?
– Rocky3582
Nov 21 at 18:59
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 at 19:09
add a comment |
I have the same error "No mapping for GET /" so no change
– Rocky3582
Nov 21 at 18:44
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 at 18:51
I didnt serve URL "/", because I thought that I can redirect welcome page in my WEB.xml to adress "/spring-mvc-login"
– Rocky3582
Nov 21 at 18:55
of course when I add this @RequestMapping("/") annotation it is working fine. But how can I redirect my welcome page to adress "/spring-mvc-login" in WEB.xml? Is this can be done only in Controller Class?
– Rocky3582
Nov 21 at 18:59
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 at 19:09
I have the same error "No mapping for GET /" so no change
– Rocky3582
Nov 21 at 18:44
I have the same error "No mapping for GET /" so no change
– Rocky3582
Nov 21 at 18:44
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 at 18:51
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 at 18:51
I didnt serve URL "/", because I thought that I can redirect welcome page in my WEB.xml to adress "/spring-mvc-login"
– Rocky3582
Nov 21 at 18:55
I didnt serve URL "/", because I thought that I can redirect welcome page in my WEB.xml to adress "/spring-mvc-login"
– Rocky3582
Nov 21 at 18:55
of course when I add this @RequestMapping("/") annotation it is working fine. But how can I redirect my welcome page to adress "/spring-mvc-login" in WEB.xml? Is this can be done only in Controller Class?
– Rocky3582
Nov 21 at 18:59
of course when I add this @RequestMapping("/") annotation it is working fine. But how can I redirect my welcome page to adress "/spring-mvc-login" in WEB.xml? Is this can be done only in Controller Class?
– Rocky3582
Nov 21 at 18:59
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 at 19:09
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 at 19:09
add a comment |
up vote
0
down vote
Try to change web.xml content:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Or change controller mapping to:
@RequestMapping(value={"/", "/spring-mvc-login"})
add a comment |
up vote
0
down vote
Try to change web.xml content:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Or change controller mapping to:
@RequestMapping(value={"/", "/spring-mvc-login"})
add a comment |
up vote
0
down vote
up vote
0
down vote
Try to change web.xml content:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Or change controller mapping to:
@RequestMapping(value={"/", "/spring-mvc-login"})
Try to change web.xml content:
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Or change controller mapping to:
@RequestMapping(value={"/", "/spring-mvc-login"})
answered Nov 21 at 18:47
Centos
17519
17519
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418424%2fno-mapping-for-get-in-springmvc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I tried this and it didnt work.
– Rocky3582
Nov 21 at 18:45