java - WARNING: No mapping found for HTTP request with URI [/SpringLoginApplication/] in DispatcherServlet with name 'SpringLoginApplication' -
my project maven project when run project on tomcat shows org.springframework.web.servlet.dispatcherservlet nohandlerfound warning: no mapping found http request uri [/springloginapplication/] in dispatcherservlet name 'springloginapplication'
i tried possibilities resolve in vein, can me out resolve issue
my controller :
package com.spring.login.controller; import javax.servlet.http.httpsession; import javax.validation.valid; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.controller; import org.springframework.ui.modelmap; import org.springframework.validation.bindingresult; import org.springframework.web.bind.annotation.*; import com.spring.login.beans.customer; import com.spring.login.services.customerservice; import com.spring.login.validation.customervalidation; @controller public class customercontroller { @autowired private customerservice customerservice; @requestmapping(value="/" , method=requestmethod.get) public string login(modelmap model){ //model.put("info", new customer()); return "/login"; } @requestmapping(value="/register", method = requestmethod.get) public string showform(modelmap model){ model.put("customerdata", new customer()); return "/register"; } @requestmapping(value= "/register", method= requestmethod.post) public string saveform(modelmap model, @modelattribute("customerdata") @valid customer customer, bindingresult br, httpsession session){ customervalidation customervalidation = new customervalidation(); customervalidation.validate(customervalidation, br); if(br.haserrors()){ return "/register"; } else{ customerservice.savecustomer(customer); session.setattribute("customer", customer); return "redirect:success"; } } @requestmapping(value="/logout", method = requestmethod.get) public string logout(modelmap model, httpsession session){ session.removeattribute("customer"); return "redirect:login"; } @requestmapping(value="/success", method = requestmethod.get) public string logout(modelmap model){ model.put("customer", new customer()); return "redirect:success"; } }
my web.xml :
<?xml version="1.0" encoding="utf-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" > <display-name>springloginapplication</display-name> <welcome-file-list> <welcome-file>home.jsp</welcome-file> <welcome-file>index.html</welcome-file> </welcome-file-list> <context-param> <param-name>contextclass</param-name> <param-value> org.springframework.web.context.support.annotationconfigwebapplicationcontext </param-value> </context-param> <listener> <listener- class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <servlet> <servlet-name>springloginapplication</servlet-name> <servlet- class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value> /web-inf/springloginapplication-servlet.xml </param-value> </init-param> <init-param> <param-name>contextclass</param-name> <param-value> org.springframework.web.context.support.annotationconfigwebapplicationcontext </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springloginapplication</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <session-config> <session-timeout>30</session-timeout> </session-config> </web-app>
my springloginapplication-servlet.xml :
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemalocation=" http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="com.spring.login.controller" /> <context:component-scan base-package="com.spring.login.dao" /> <context:component-scan base-package="com.spring.login.beans" /> <context:component-scan base-package="com.spring.login.services" /> <context:component-scan base-package="com.spring.login.validation" /> <mvc:annotation-driven /> <context:annotation-config /> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/views/" /> <property name="suffix" value=".jsp" /> </bean> <bean class="com.spring.login.beans.customer" init-method="getc_id" destroy- method="getc_name"> <property name="c_id" value="1234"/> <property name="c_name" value="sanjay"/> </bean> </beans>
a working response highly appreciated!
any other info required, pls let me know
i had same problem few days before, , got bellow solution.
@controller @requestmapping(value="/" ) public class customercontroller { //do stuff here @requestmapping(method=requestmethod.get) public string login(modelmap model){ //model.put("info", new customer()); return "/login"; } //rest of stuff goes here
}
since have configured dispatcher servlet handle context in stead of possibility people adding (/*), above provided code snippet work , redirect context /login want(if i'm not wrong). cheers!!!!
Comments
Post a Comment