java - Spring controller not showing the relevent view -
i've got following spring controller class.
@controller public class layoutcontroller { @requestmapping(value = "/layout", method = requestmethod.get) public string showlayout(){ return "redirect:/views/layout.html"; } } this common-config xml.
<?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" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" 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-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> <!-- common configurations --> <mvc:annotation-driven/> <tx:annotation-driven/> <bean id="viewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver" p:prefix="/web-inf/views/" p:suffix=".html" /> <!-- annotations based configuration --> <context:annotation-config /> <mvc:resources mapping="/*" location="/web-inf/views/" /> <!-- components auto-detection (backend) --> <context:component-scan base-package="com.jkcs.touchpos" use-default-filters="false" > <!-- types annotated spring managed, controller , transactional, or annotation annotated springmanaged, controller, transactional --> <context:include-filter type="annotation" expression="com.jkcs.touchpos.platform.annotations.springmanaged"/> <context:include-filter type="annotation" expression="org.springframework.stereotype.controller"/> <context:include-filter type="annotation" expression="org.springframework.transaction.annotation.transactional"/> </context:component-scan> <bean class="org.springframework.web.servlet.mvc.support.controllerclassnamehandlermapping" /> </beans> this mvc-config xml file
<?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" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" 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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <bean class="org.springframework.web.servlet.mvc.annotation.defaultannotationhandlermapping" /> <bean class="org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter" /> </beans> this web.xml file.
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="webapp_id" version="2.5"> <display-name>touchpos</display-name> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app> finally dispatcher servlet :
<?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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- specific configurations --> <import resource="springconfigurations/common-config.xml"/> <import resource="springconfigurations/mvc-config.xml"/> </beans> when run web app on jetty server, , use following url layout. server throws 404 error. please me identify wrong thing i'm doing?
http://localhost:8080/touchposapplicatio/layout update : web page elements show no css. , console printed following error.
apr 19, 2013 2:17:42 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/touchposapplication/style/style.css] in dispatcherservlet name 'dispatcher' apr 19, 2013 2:17:42 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/touchposapplication/style/jquery.custom-scrollbar.css] in dispatcherservlet name 'dispatcher' apr 19, 2013 2:17:42 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/touchposapplication/js/jquery-1.9.1.min.js] in dispatcherservlet name 'dispatcher' apr 19, 2013 2:17:42 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/touchposapplication/js/jquery.colorbox.js] in dispatcherservlet name 'dispatcher' apr 19, 2013 2:17:42 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/touchposapplication/js/jquery.touchswipe.min.js] in dispatcherservlet name 'dispatcher' apr 19, 2013 2:17:42 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/touchposapplication/js/functions.js] in dispatcherservlet name 'dispatcher' apr 19, 2013 2:17:42 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/touchposapplication/js/dragscrollable.js] in dispatcherservlet name 'dispatcher' apr 19, 2013 2:17:42 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/touchposapplication/js/jquery-ui.js] in dispatcherservlet name 'dispatcher' apr 19, 2013 2:17:42 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/touchposapplication/style/colorbox.css] in dispatcherservlet name 'dispatcher' apr 19, 2013 2:17:42 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/touchposapplication/js/jquery.colorbox.js] in dispatcherservlet name 'dispatcher' apr 19, 2013 2:17:42 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/touchposapplication/js/functions.js] in dispatcherservlet name 'dispatcher' apr 19, 2013 2:17:42 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/touchposapplication/js/jquery.touchswipe.min.js] in dispatcherservlet name 'dispatcher' apr 19, 2013 2:17:42 pm org.springframework.web.servlet.pagenotfound nohandlerfound warning: no mapping found http request uri [/touchposapplication/js/dragscrollable.js] in dispatcherservlet name 'dispatcher'
i assume touchposapplicatio typo in question? i'm strugglig understand pattern here. have mapped static resources /web-inf/views, not accesible browser, don't think that'll work. try putting regular webapp folder instead, static (at same level web-inf). change config to:
<mvc:resources mapping="/static/**" location="/static"/> and can verify can accessed typing http://localhost:8080/touchposapplication/static/layout.html. if works, have configured static resources correctly.
edit
if have css resources also, make sure add folder resources mvc:resource.
Comments
Post a Comment