我正在尝试显示一个表单并使用spring mvc提交。当我运行这个项目时,它显示表单但是一旦我点击提交它显示404错误“原始服务器没有找到目标资源的当前表示或者不愿意透露那个存在。”我不明白是什么导致了这个问题。
servlet的context.xml中
<annotation-driven />
<resources mapping="/resources/**" location="/resources/" />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.swet.springform" />
的web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
控制器类
@RequestMapping(value="/", method=RequestMethod.GET)
public ModelAndView welcomePage()
{
ModelAndView mv = new ModelAndView("home");
mv.addObject("command", new Customer());
return mv;
}
@RequestMapping(value="/success", method=RequestMethod.POST)
public ModelAndView successPage()
{
ModelAndView mv = new ModelAndView("success");
mv.addObject("command", new Customer());
return mv;
}
针对home.jsp
<form:form method="post" action="/success">
<form:errors path="*" cssClass="errorblock" element="div" />
<table>
<tr>
<td>Username :</td>
<td><form:input path="userName" />
</td>
<td><form:errors path="userName" cssClass="error" />
</td>
</tr>
<tr>
<td>Password :</td>
<td><form:input path="userName"/>
</td>
<td><form:errors path="password" cssClass="error" />
</td>
</tr>
<tr>
<td>Confirm Password :</td>
<td><form:input path="confirmPassword" />
</td>
<td><form:errors path="confirmPassword" cssClass="error" />
</td>
</tr>
<tr>
<td colspan="3"><input type="submit" />
</td>
</tr>
</table>
</form:form>
这是我的目录结构: