No mapping for GET / in SpringMVC
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 |
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 '18 at 18:45
add a comment |
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 '18 at 18:28
Rocky3582Rocky3582
5117
5117
I tried this and it didnt work.
– Rocky3582
Nov 21 '18 at 18:45
add a comment |
I tried this and it didnt work.
– Rocky3582
Nov 21 '18 at 18:45
I tried this and it didnt work.
– Rocky3582
Nov 21 '18 at 18:45
I tried this and it didnt work.
– Rocky3582
Nov 21 '18 at 18:45
add a comment |
3 Answers
3
active
oldest
votes
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 '18 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 '18 at 18:57
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 '18 at 19:04
add a comment |
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 '18 at 18:44
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 '18 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 '18 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 '18 at 18:59
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 '18 at 19:09
add a comment |
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 '18 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 '18 at 18:57
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 '18 at 19:04
add a comment |
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 '18 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 '18 at 18:57
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 '18 at 19:04
add a comment |
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 '18 at 18:42
Denis KovzelyukDenis Kovzelyuk
716
716
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 '18 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 '18 at 18:57
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 '18 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 '18 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 '18 at 18:57
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 '18 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 '18 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 '18 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 '18 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 '18 at 18:57
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 '18 at 19:04
spring.io/guides/gs/securing-web
– Denis Kovzelyuk
Nov 21 '18 at 19:04
add a comment |
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 '18 at 18:44
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 '18 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 '18 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 '18 at 18:59
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 '18 at 19:09
add a comment |
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 '18 at 18:44
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 '18 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 '18 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 '18 at 18:59
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 '18 at 19:09
add a comment |
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 '18 at 18:43
JoseJose
937
937
I have the same error "No mapping for GET /" so no change
– Rocky3582
Nov 21 '18 at 18:44
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 '18 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 '18 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 '18 at 18:59
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 '18 at 19:09
add a comment |
I have the same error "No mapping for GET /" so no change
– Rocky3582
Nov 21 '18 at 18:44
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 '18 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 '18 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 '18 at 18:59
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 '18 at 19:09
I have the same error "No mapping for GET /" so no change
– Rocky3582
Nov 21 '18 at 18:44
I have the same error "No mapping for GET /" so no change
– Rocky3582
Nov 21 '18 at 18:44
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 '18 at 18:51
You are missing these annotations in your controller class @Controller @RequestMapping("/")
– Jose
Nov 21 '18 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 '18 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 '18 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 '18 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 '18 at 18:59
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 '18 at 19:09
Is there any reason in particular? Spring facilitates this with only return a String, it is the new
– Jose
Nov 21 '18 at 19:09
add a comment |
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 |
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 |
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 '18 at 18:47
CentosCentos
20019
20019
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.
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 '18 at 18:45