java - Spring web project failure -
i have spring helloworld project developed me , library management used maven in project. intention see how spring handles url requests.
i think developed correctly but, outcome not achieved.
i have entered controller class, web.xml file , mvc-dispatcher-servlet.xml files here.
controller class
import org.springframework.stereotype.controller; import org.springframework.ui.modelmap; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; @controller @requestmapping("/welcome") public class accesscontroller { //@requestmapping(value = {"/welcome"}, method = requestmethod.get) @requestmapping(method=requestmethod.get) public string printwelcome(modelmap model){ system.out.println("there in access atempt"); model.addattribute("message","hello spring web mvc !!!"); return "hello"; } }
web.xml
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="webapp_id" version="3.0"> <display-name>springlms</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/mvc-dispatcher-servlet.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> </web-app>
mvc-dispatcher-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" xsi:schemalocation=" 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.vigamage.controller" /> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix"> <value>/web-inf/jsp/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans>
according way have coded, when enter url http://localhost:8080/springlms/welcome
jsp page should shown.
but output http status 404, requested resource not available
it not come in controller class think.(because not print sentence on console have put there in controller class.)
i cannot figure out mistake have done here. if find out have done wrong, please point out.
this folder structure.
edit
the server output
oct 03, 2015 1:52:56 pm org.apache.tomcat.util.digester.setpropertiesrule begin warning: [setpropertiesrule]{server/service/engine/host/context} setting property 'source' 'org.eclipse.jst.jee.server:springlms' did not find matching property. oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: server version: apache tomcat/7.0.64 oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: server built: aug 19 2015 17:18:06 utc oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: server number: 7.0.64.0 oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: os name:
windows 8.1 oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: os version: 6.3 oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: architecture: amd64 oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: java home: c:\program files\java\jre7 oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: jvm version: 1.7.0_79-b15 oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: jvm vendor: oracle corporation oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: catalina_base: c:\users\viraj gamage\documents\eclipsemars.metadata.plugins\org.eclipse.wst.server.core\tmp1 oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: catalina_home: c:\users\viraj gamage\documents\eclipsemars\tomcat7\apache-tomcat-7.0.64 oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: command line argument: -dcatalina.base=c:\users\viraj gamage\documents\eclipsemars.metadata.plugins\org.eclipse.wst.server.core\tmp1 oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: command line argument: -dcatalina.home=c:\users\viraj gamage\documents\eclipsemars\tomcat7\apache-tomcat-7.0.64 oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: command line argument: -dwtp.deploy=c:\users\viraj gamage\documents\eclipsemars.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: command line argument: -djava.endorsed.dirs=c:\users\viraj gamage\documents\eclipsemars\tomcat7\apache-tomcat-7.0.64\endorsed oct 03, 2015 1:52:56 pm org.apache.catalina.startup.versionloggerlistener log info: command line argument: -dfile.encoding=cp1252 oct 03, 2015 1:52:56 pm org.apache.catalina.core.aprlifecyclelistener lifecycleevent info: apr based apache tomcat native library allows optimal performance in production environments not found on java.library.path: c:\program files\java\jre7\bin;c:\windows\sun\java\bin;c:\windows\system32;c:\windows;c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowspowershell\v1.0\;c:\program files\java\jdk1.7.0_79\bin;c:\program files\matlab\r2013a\runtime\win64;c:\program files\matlab\r2013a\bin;c:\apache\apache-maven-3.3.3\bin;c:\program files\java\jdk1.7.0_79\bin;c:\program files (x86)\sox-14-4-2;;. oct 03, 2015 1:52:56 pm org.apache.coyote.abstractprotocol init info: initializing protocolhandler ["http-bio-8080"] oct 03, 2015 1:52:56 pm org.apache.coyote.abstractprotocol init info: initializing protocolhandler ["ajp-bio-8009"] oct 03, 2015 1:52:56 pm org.apache.catalina.startup.catalina load info: initialization processed in 775 ms oct 03, 2015 1:52:56 pm org.apache.catalina.core.standardservice startinternal info: starting service catalina oct 03, 2015 1:52:56 pm org.apache.catalina.core.standardengine startinternal info: starting servlet engine: apache tomcat/7.0.64 oct 03, 2015 1:52:57 pm org.apache.catalina.util.sessionidgeneratorbase createsecurerandom info: creation of securerandom instance session id generation using [sha1prng] took [102] milliseconds. oct 03, 2015 1:52:58 pm org.apache.catalina.startup.tldconfig execute info: @ least 1 jar scanned tlds yet contained no tlds. enable debug logging logger complete list of jars scanned no tlds found in them. skipping unneeded jars during scanning can improve startup time , jsp compilation time. oct 03, 2015 1:52:58 pm org.apache.catalina.core.applicationcontext log info: no spring webapplicationinitializer types detected on classpath oct 03, 2015 1:52:58 pm org.apache.coyote.abstractprotocol start info: starting protocolhandler ["http-bio-8080"] oct 03, 2015 1:52:58 pm org.apache.coyote.abstractprotocol start info: starting protocolhandler ["ajp-bio-8009"] oct 03, 2015 1:52:58 pm org.apache.catalina.startup.catalina start info: server startup in 1829 ms
1) forgot declare spring context loader, please add in web.xml :
<listener> <display-name>spring context loader</display-name> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener>
2) achieve add mvc:annotation-driven element in dispatcherservlet context, declares explicit support annotation-driven mvc controllers (i.e. @requestmapping
, @controller
, ...)
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <mvc:annotation-driven /> [...] </beans>
Comments
Post a Comment