Monday, 15 July 2013

java - Spring 3.2 MVC - Cannot match URL with Controller -



java - Spring 3.2 MVC - Cannot match URL with Controller -

i'm trying start new application scratch spring 3.2, , got 404 error when seek access controller. here configuration:

web-inf web.xml web-context.xml

web.xml:

<!doctype web-app public "-//sun microsystems, inc.//dtd web application 2.3//en" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>archetype created web application</display-name> <context-param> <param-name>contextconfiglocation</param-name> <param-value> /web-inf/application-context.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <servlet> <servlet-name>appservlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/web-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appservlet</servlet-name> <url-pattern>/deblan/*</url-pattern> </servlet-mapping> </web-app>

web-context.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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" 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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com.deboralandini.web.controllers"/> <mvc:annotation-driven/> <beans> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/views/"/> <property name="suffix" value=".jsp"/> </bean> </beans> </beans>

my controller:

bundle com.deboralandini.web.controllers; import ...; @controller @requestmapping("cuenta") public class cuentacontroller { @autowired private cuentaservice cuentaservice; ... @requestmapping(value = "/ccuenta") public string ccuenta(model model){ homecoming "crearcuenta"; } ... }

my index.jsp:

<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form" %> <html> <body> <h2>blabla</h2> <br/> <a href="cuenta/ccuenta">crear cuenta</a> </body> </html>

unfortunately, when click link, get:

status http 404 - /deblan/cuenta/ccuenta

the browser tries create http://localhost:8080/deblan/cuenta/ccuenta, cannot in controller. debugged controller , in fact not entering there, so: whats newbie error?

thanks in advance marcos

edit: output:

"c:\...\app\tomcat8\bin\catalina.bat" run [2014-10-21 08:57:21,069] artifact deblan:war: server not connected. deploy not available. using catalina_base: ... connected target vm, address: '127.0.0.1:64352', transport: 'socket' 21-oct-2014 20:57:21.743 info [main] org.apache.catalina.startup.versionloggerlistener.log server version: apache tomcat/8.0.14 21-oct-2014 20:57:21.745 info [main] org.apache.catalina.startup.versionloggerlistener.log server built: sep 24 2014 09:01:51 21-oct-2014 20:57:21.745 info [main] org.apache.catalina.startup.versionloggerlistener.log server number: 8.0.14.0 21-oct-2014 20:57:21.745 info [main] org.apache.catalina.startup.versionloggerlistener.log os name: windows 8.1 21-oct-2014 20:57:21.745 info [main] org.apache.catalina.startup.versionloggerlistener.log os version: 6.3 21-oct-2014 20:57:21.745 info [main] org.apache.catalina.startup.versionloggerlistener.log architecture: amd64 21-oct-2014 20:57:21.745 info [main] org.apache.catalina.startup.versionloggerlistener.log jvm version: 1.7.0_55-b13 21-oct-2014 20:57:21.745 info [main] org.apache.catalina.startup.versionloggerlistener.log jvm vendor: oracle corporation 21-oct-2014 20:57:21.924 info [main] org.apache.catalina.core.aprlifecyclelistener.init cargada la biblioteca nativa apr de apache tomcat 1.1.31 con la versiĆ³n apr 1.4.8. 21-oct-2014 20:57:21.924 info [main] org.apache.catalina.core.aprlifecyclelistener.init capacidades apr: ipv6 [true], enviar fichero [true], aceptar filtros [false], aleatorio [true]. 21-oct-2014 20:57:22.551 info [main] org.apache.catalina.core.aprlifecyclelistener.initializessl openssl inicializado correctamente (openssl 1.0.1h 5 jun 2014) 21-oct-2014 20:57:22.649 info [main] org.apache.coyote.abstractprotocol.init initializing protocolhandler ["http-apr-8080"] 21-oct-2014 20:57:22.662 info [main] org.apache.coyote.abstractprotocol.init initializing protocolhandler ["ajp-apr-8009"] 21-oct-2014 20:57:22.664 info [main] org.apache.catalina.startup.catalina.load initialization processed in 992 ms 21-oct-2014 20:57:22.695 info [main] org.apache.catalina.core.standardservice.startinternal arrancando servicio catalina 21-oct-2014 20:57:22.695 info [main] org.apache.catalina.core.standardengine.startinternal starting servlet engine: apache tomcat/8.0.14 21-oct-2014 20:57:22.708 info [main] org.apache.coyote.abstractprotocol.start starting protocolhandler ["http-apr-8080"] 21-oct-2014 20:57:22.719 info [main] org.apache.coyote.abstractprotocol.start starting protocolhandler ["ajp-apr-8009"] 21-oct-2014 20:57:22.722 info [main] org.apache.catalina.startup.catalina.start server startup in 57 ms connected server [2014-10-21 08:57:23,165] artifact deblan:war: artifact beingness deployed, please wait... slf4j: failed load class "org.slf4j.impl.staticloggerbinder". slf4j: defaulting no-operation (nop) logger implementation slf4j: see http://www.slf4j.org/codes.html#staticloggerbinder farther details. log4j:warn no appenders found logger (org.jboss.logging). log4j:warn please initialize log4j scheme properly. log4j:warn see http://logging.apache.org/log4j/1.2/faq.html#noconfig more info. [2014-10-21 08:57:32,003] artifact deblan:war: artifact deployed [2014-10-21 08:57:32,003] artifact deblan:war: deploy took 8,838 milliseconds 21-oct-2014 20:57:32.712 info [localhost-startstop-1] org.apache.catalina.startup.hostconfig.deploydirectory despliegue del directorio c:...\app\tomcat8\webapps\manager de la aplicaciĆ³n web 21-oct-2014 20:57:32.762 info [localhost-startstop-1] org.apache.catalina.startup.hostconfig.deploydirectory deployment of web application directory c:...\app\tomcat8\webapps\manager has finished in 50 ms

if deblan context root don't set in servlet mapping. you've got url:

http://localhost:8080/deblan/cuenta/ccuenta

if you've deployed app deblan context root then:

http://localhost:8080/deblan

takes app

/cuenta/ccuenta

now maps controller, try:

<servlet-mapping> <servlet-name>appservlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>

which means http://localhost:8080/deblan + whatever comes after.

java spring spring-mvc controller

No comments:

Post a Comment