java - @RequestMapping("/main") does not work in netbeans spring 4 it is working in spring 3 -


@requestmapping("/main") not work in netbeans spring 4 working in spring 3. same thing when using in spring framework 3.0 compleletly working fine dont know why not working in spring framework 4.

when trying open url: http://localhost:8080/anotationmultiactiondemo/main not going open.

please me......

dispatcher-servlet.xml

<?xml version='1.0' encoding='utf-8' ?> <!-- was: <?xml version="1.0" encoding="utf-8"?> --> <beans xmlns="http://www.springframework.org/schema/beans"        xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"        xmlns:p="http://www.springframework.org/schema/p"        xmlns:aop="http://www.springframework.org/schema/aop"        xmlns:tx="http://www.springframework.org/schema/tx"        xsi:schemalocation="http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">      <context:component-scan base-package="mylcontroller" />      <bean id="viewresolver"           class="org.springframework.web.servlet.view.internalresourceviewresolver"           p:prefix="/web-inf/jsp/"           p:suffix=".jsp" />   </beans> 

maincontroller

/*  * change license header, choose license headers in project properties.  * change template file, choose tools | templates  * , open template in editor.  */ package mylcontroller;  import org.springframework.web.servlet.modelandview; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.stereotype.controller; /**  *  * @author juned ansari  */ @controller public class maincontroller {     @requestmapping("/main")     public modelandview hithere() {          modelandview mav = new modelandview("index");         mav.addobject("welcomemessage", "hi there");          return mav;     } } 

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">     <init-param>         <param-name>contextconfiglocation</param-name>         <param-value>/web-inf/applicationcontext.xml</param-value>     </init-param>     <context-param>         <param-name>contextconfiglocation</param-name>         <param-value>/web-inf/applicationcontext.xml</param-value>     </context-param>     <listener>         <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>     </listener>     <servlet>         <servlet-name>dispatcher</servlet-name>         <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>         <load-on-startup>2</load-on-startup>     </servlet>     <servlet-mapping>         <servlet-name>dispatcher</servlet-name>         <url-pattern>/</url-pattern>     </servlet-mapping>     <session-config>         <session-timeout>             30         </session-timeout>     </session-config>     <welcome-file-list>         <welcome-file>redirect.jsp</welcome-file>     </welcome-file-list> </web-app> 

during analysis on code ( pressumably have brain )

1).missing xmlns:context="http://www.springframework.org/schema/context" enable <context:component-scan>

2). why use? (i think you're not having such applicationcontext.xml there in web-inf) beside don't have such file commented otherwise throw error

 <!--    <init-param>         <param-name>contextconfiglocation</param-name>         <param-value>/web-inf/applicationcontext.xml</param-value>     </init-param>     <context-param>         <param-name>contextconfiglocation</param-name>         <param-value>/web-inf/applicationcontext.xml</param-value>     </context-param>     <listener>         <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>     </listener>--> 

3). changed xsi : schemalocation

 xsi:schemalocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-4.0.xsd     http://www.springframework.org/schema/context     http://www.springframework.org/schema/context/spring-context-4.0.xsd" 

4). incompatibility stuff in spring 4 can't afford explain .

so here's fixed codes:

enter image description here

maincontroller.java

package mylcontroller;  import org.springframework.web.servlet.modelandview; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.stereotype.controller; /**  *  * @author juned ansari  */ @controller public class maincontroller {     @requestmapping("/main")     public modelandview hithere() {          modelandview mav = new modelandview();         mav.setviewname("index");         mav.addobject("welcomemessage", "hi there");          return mav;     } } 

dispatcher-servlet.xml

<?xml version="1.0" encoding="utf-8"?>   <beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"       xmlns:p="http://www.springframework.org/schema/p"       xmlns:context="http://www.springframework.org/schema/context"       xsi:schemalocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-4.0.xsd   http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-4.0.xsd">       <context:component-scan base-package="mylcontroller"/>       <bean id="viewresolver"           class="org.springframework.web.servlet.view.internalresourceviewresolver"           p:prefix="/web-inf/jsp/"           p:suffix=".jsp" />     </beans> 

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"> <!--    <init-param>         <param-name>contextconfiglocation</param-name>         <param-value>/web-inf/applicationcontext.xml</param-value>     </init-param>     <context-param>         <param-name>contextconfiglocation</param-name>         <param-value>/web-inf/applicationcontext.xml</param-value>     </context-param>     <listener>         <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>     </listener>-->     <servlet>         <servlet-name>dispatcher</servlet-name>         <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>         <load-on-startup>2</load-on-startup>     </servlet>     <servlet-mapping>         <servlet-name>dispatcher</servlet-name>         <url-pattern>/</url-pattern>     </servlet-mapping>    <session-config>         <session-timeout>             30         </session-timeout>     </session-config>-->    <welcome-file-list>         <welcome-file>redirect.jsp</welcome-file>     </welcome-file-list> </web-app> 

index.jsp

<%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html> <html>     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8">         <title>jsp page</title>     </head>     <body>        ${welcomemessage}     </body> </html> 

now request http://localhost:8080/anotationmultiactiondemo/main


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -