My Spring application does not open another page -
i have created spring application using netbeans, did not alter of configuration. in index.jsp have link page not sec page , shows "the requested resource () not available."
in server console shows next warning
"warning: no mapping found http request uri [/myapp/emp.htm] in dispatcherservlet name 'dispatcher'"
my emp.jsp file in jsp folder.
index.jsp
<%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>welcome spring web mvc project</title> </head> <body> <a href="emp.htm">emp</a> </body> </html>
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: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-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean class="org.springframework.web.servlet.mvc.support.controllerclassnamehandlermapping"/> <!-- controllers utilize controllerclassnamehandlermapping above, index controller using parameterizableviewcontroller, must define explicit mapping it. --> <bean id="urlmapping" class="org.springframework.web.servlet.handler.simpleurlhandlermapping"> <property name="mappings"> <props> <prop key="index.htm">indexcontroller</prop> </props> </property> </bean> <bean id="viewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver" p:prefix="/web-inf/jsp/" p:suffix=".jsp" /> <!-- index controller. --> <bean name="indexcontroller" class="org.springframework.web.servlet.mvc.parameterizableviewcontroller" p:viewname="index" /> <bean name="/emp.htm" class="controller.employee"/> <<i changed "/myapp/emp.htm" not work </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"> <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>*.htm</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>
employee.java
/* * alter template, take tools | templates * , open template in editor. */ bundle controller; import org.springframework.web.servlet.mvc.controller; import org.springframework.web.servlet.modelandview; import javax.servlet.servletexception; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import org.apache.commons.logging.log; import org.apache.commons.logging.logfactory; import java.io.ioexception; public class employee implements controller { protected final log logger = logfactory.getlog(getclass()); @override public modelandview handlerequest(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { logger.info("returning hello view"); homecoming new modelandview("emp.jsp"); } }
change <a href>
actual url this
<a href="<c:url value="/emp"/>" />
also create sure dispatcher servlet
mapped in web.xml
<servlet> <servlet-name>dispatcherservlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherservlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
more spring mvc implementation can found here
spring spring-mvc
No comments:
Post a Comment