我创建了一个非常小的弹簧网络应用程序但是无法使用eclipse在tomcat上部署它。我可以在日志中看到Web应用程序被初始化。但是tomcat实际上并没有部署它,如果我尝试去URL,我会得到404错误资源不可用。我在这里错过了什么吗?
Web xml
<web-app 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">
<servlet>
<servlet-name>MNPUI</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MNPUI</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>
home.jsp
</welcome-file>
</welcome-file-list>
</web-app>
MNPUI-servlet.xml中
<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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.doyleisgod.mnpui.controllers"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
的HomeController
package com.doyleisgod.mnpui.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping("/home.jsp")
public String home (ModelMap model){
model.addAttribute("message", "Welcome");
return "home";
}
}
针对home.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Home</title>
</head>
<body>
${message}
</body>
</html>
Eclipse控制台日志
03-Sep-2014 13:33:11 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre7/bin/client;C:/Program Files (x86)/Java/jre7/bin;C:/Program Files (x86)/Java/jre7/lib/i386;C:\Perl\site\bin;C:\Perl\bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Dell\Dell Data Protection\Access\Advanced\Wave\Gemalto\Access Client\v5\;C:\Program Files (x86)\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;C:\Program Files\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Users\CD00119621\Desktop\eclipse\eclipse;;.
03-Sep-2014 13:33:11 org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:MNPUI' did not find a matching property.
03-Sep-2014 13:33:11 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
03-Sep-2014 13:33:11 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
03-Sep-2014 13:33:11 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 681 ms
03-Sep-2014 13:33:11 org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
03-Sep-2014 13:33:11 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.37
03-Sep-2014 13:33:14 org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
03-Sep-2014 13:33:14 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'MNPUI'
03-Sep-2014 13:33:15 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\CD00119621\apache-tomcat-7.0.37\webapps\docs
03-Sep-2014 13:33:15 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\CD00119621\apache-tomcat-7.0.37\webapps\host-manager
03-Sep-2014 13:33:15 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\CD00119621\apache-tomcat-7.0.37\webapps\manager
03-Sep-2014 13:33:15 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Users\CD00119621\apache-tomcat-7.0.37\webapps\ROOT
03-Sep-2014 13:33:15 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
03-Sep-2014 13:33:15 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
03-Sep-2014 13:33:15 org.apache.catalina.startup.Catalina start
INFO: Server startup in 3760 ms
答案 0 :(得分:0)
您需要将以下行添加到web.xml文件
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>/WEB-INF/jsp/*</url-pattern>
</servlet-mapping>
大多数servlet容器都有一个从*.jsp
到它们自己的JSP处理器的默认映射。