我有一个简单的 spring 3 mvc 应用程序,它只是在有人浏览到 http://localhost:8080/ 时输出 index.aspx。
当我执行 RunAs 并在服务器选项(连接到 tomcat 6)上运行时,它打开浏览器到 http://localhost:8080/springmvc2/ (其中 springmvc2 是应用程序名称)。
我已经使用 netbeans 构建了这个相同的简单测试应用程序,它使用 url http://localhost:8080/ 工作正常
我的 web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Springmvc2</display-name>
<description>Springmvc2 web application</description>
<servlet>
<servlet-name>Springmvc2</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Maps all /app requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>Springmvc2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
我的 HomeController 是:
package com.springmvc2.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class HomeController {
@RequestMapping("/")
public String Index(){
return "index";
}
@RequestMapping("/test")
public String Index2(){
return "index";
}
}
您可以在此处查看我的 pom.xml 文件:Using eclipse with maven plugin, how should I setup my build so it deploys to tomcat?
这也是生成的目标文件夹:
/target
/target/springmvc2/meta-inf
/target/springmvc2/web-inf
/target/springmvc2/test.html
/target/war/springmvc2.war
/target/pom.xml
我创建 test.html 只是为了看看是否至少可以呈现,但是 http://localhost:8080
/test.html 不起作用,并且 http://localhost :8080/springvc2/test.html
也不起作用。
我收到 404 错误,所以我猜它没有正确部署到 tomcat,特别是因为 test.html 文件甚至没有呈现。
但也许 test.html 没有呈现,因为我的 springmvc2-servlet.xml
中有这个:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" p:order="2"/>
我不得不承认,Java 开发充满了配置问题,尤其是对于新手!!
更新
编译并执行 runas 服务,打开浏览器,我从 tomcat 收到此消息:
WARNING: No mapping found for HTTP request with URI [/springmvc2/] in DispatcherServlet with name 'springmvc2'
最佳答案
网址应为 http://localhost:8080/springmvc2/test.html (您粘贴的那个中缺少 m
)。
更新:尝试<url-pattern>/*</url-pattern>
而不是 <url-pattern>/</url-pattern>
关于java - 通过 eclipse 和 maven2 插件部署到 tomcat 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2238715/