我正在开发一个Java应用程序,并且我正在使用Spring MVC。我是新手,我试图在我的主页中加载一些静态内容,如css文件和图像。当我尝试加载其中一些文件时,我收到405错误(不允许使用GET方法)。
我的项目结构(对于网络部分)是
-WebContent
--MetaInf
--resources
--views
--WEB_INF
---web.xml
---springapp-dispatcher.xml
这是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="true">
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
我的springapp-dispatcher.xml(没有初始部分)
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**"
location="/resources/" />
<context:component-scan base-package="polibeacon.web"></context:component-scan>
<bean class= "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
我只有一个名为HomeController.java的控制器
@Controller
public class HomeController {
@RequestMapping( value = "/", method = RequestMethod.GET )
public String index(Model model) {
model.addAttribute(new User());
return "index";
}
@RequestMapping(value="/registration", method = RequestMethod.GET)
public String registration(Model model) {
model.addAttribute(new User());
return "registration";
}
@RequestMapping(method=RequestMethod.POST)
public String registerUser(@Valid User user, BindingResult bindingResult) {
if(bindingResult.hasErrors()) {
return "registration";
}
// save user
return "index";
}
}
这里是index.jsp页面
<!-- CSS -->
<link href="<c:url value="/resources/bootstrap/css/bootstrap.min.css" />" rel = "stylesheet">
<link href="<c:url value="/resources/css/style.css" />" rel = "stylesheet">
<!-- Scripts -->
</head>
<body>
<div class = "container">
<div class = "row">
<div class = "col-md-3"></div>
<div class = "col-md-6">
<div class = "jumbotron" style = "text-align: center;">
<img src = "images/logo.png" style = "display: block; margin-left: auto; margin-right: auto;">
<h2>Header</h2>
<form:form method="post" modelAttribute="user">
<form:input path="username" placeholder="Username"/>
<form:password path="password" placeholder="Password"/>
</form:form>
</div>
</div>
</div>
<a href="<c:url value="registration"/>">Sign Up</a>
</div>
</body>
</html>
出了什么问题?