我得到下面的錯誤,而從瀏覽器訪問http://localhost:8080/test_jboss_local/welcome
網址:在DispatcherServlet的發現HTTP請求與URI [/ test_jboss_local /歡迎]與名沒有映射「appServlet」
No mapping found for HTTP request with URI [/test_jboss_local/welcome] in DispatcherServlet with name 'appServlet'
下面是這些文件:
的web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
</param-value>
</context-param>
<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/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
的servlet-context.xml中:
<annotation-driven />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
根context.xml中:
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<context:component-scan base-package="com.abc" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- <property name="dataSource" ref="dataSource" /> -->
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
HelloController.java:
@Controller
public class HelloController {
@RequestMapping(value="/welcome", method = RequestMethod.GET)
public String welcome(ModelMap model) {
model.addAttribute("message", "Maven Web Project + Spring 3 MVC - welcome()");
//Spring uses InternalResourceViewResolver and return back index.jsp
return "index";
}
@RequestMapping(value="/welcome/{name}", method = RequestMethod.GET)
public String welcomeName(@PathVariable String name, ModelMap model) {
model.addAttribute("message", "Maven Web Project + Spring 3 MVC - " + name);
return "index";
}
的index.jsp:
<html>
<body>
<h2>Hello World!</h2>
<h4>Message : ${message}</h1>
</body>
</html>
我查網,我不能夠識別錯誤。請幫忙。
您的應用程序未成功部署。嘗試重新部署應用程序,看看是否在系統日誌中出現任何異常。 – jsjunkie 2014-09-01 07:42:56
它部署成功..沒有發生異常。 – VJS 2014-09-01 07:43:40
如果你的控制器不在默認包中,那麼在spring-context.xml中添加 \t
jsjunkie
2014-09-01 07:48:05