我是Spring MVC和Maven的新手。我在eclipse中創建了一個maven web項目。爲spring添加依賴關係並運行該項目,但我沒有得到期望的結果。這裏是我的項目結構Spring MVC未顯示預期結果
當我運行該項目,然後我得到的結果Hello World
這是我的index.jsp
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Hello</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
但是,當我改變URL http://localhost:8080/Spring_Maven/jsp/hello
我得到HTTP Status 500 error
。當我改變URL http://localhost:8080/Spring_Maven/jsp/hello.jsp
然後我得到的輸出${message}
,這裏是我的hello.jsp頁面
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Hello</title>
</head>
<body>
<h1>${message}</h1>
</body>
</html>
這裏是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring_Maven</display-name>
<servlet>
<servlet-name>springMaven-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMaven-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springMaven-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
這裏是我的springMaven,調度員-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<context:component-scan base-package="pk.training.basitMahmood.springMaven.controller" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
這裏是依賴項列表tha T I基於Maven
添加什麼,我做錯了什麼?
我在搜索過程中發現的一件事是,maven依賴項應該複製到'WEB-INF/lib'文件夾中。但它不是複製。雖然當我去'項目屬性 - >部署大會'我有'Meven依賴映射到WEB-INF/lib'。但是我的WEB-INF中沒有lib文件夾。我還不知道是否需要手動創建該文件夾。我也嘗試通過手動創建文件夾,但罐子不復制到lib文件夾不知道爲什麼......但這是我的發現,直到:) – Basit 2013-05-09 10:56:07