我创建了一个Spring-Hibernate Web应用程序,它可以在码头服务器上完美运行。
但是,当我在tomcat上运行它时,它没有任何错误地成功运行,但是我无法在Web浏览器上使用该应用程序,Web浏览器上没有任何显示(甚至没有错误。)>
下面是详细信息:
这是应用程序成功开始使用Jetty服务器的地方。
http://localhost:8080/contacts
这是我为之定义控制器的地方。
@Controller public class ContactController { @Autowired private ContactRepository contactRepository; @RequestMapping(value = "/contacts", method = RequestMethod.GET) public String getContactList(Model model) { model.addAttribute("contacts", contactRepository.findAll()); return "contact/list"; } }
web.xml文件。
<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_3_0.xsd" version="3.0"> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>/view/*</url-pattern> </servlet-mapping> <filter> <filter-name>openEntityManagerInViewFilter</filter-name> <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class> <init-param> <param-name>entityManagerFactoryBeanName</param-name> <param-value>entityManagerFactory</param-value> </init-param> </filter> <filter-mapping> <filter-name>openEntityManagerInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>
下面是spring-servlet.xml文件
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com.marakana.contacts.controllers" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
我已经创建了一个Spring-Hibernate Web应用程序,它可以在码头服务器上完美运行。但是,当我在tomcat上运行它时,它成功运行,没有错误,但是我无法使用...
也许对于tomcat的URL应该是http://localhost:8080/yourWarName/contacts