Java spring mvc中未调用控制器
我是SpringMVC的初学者。我试图使用SpringMVC创建一个登录页面。但我的控制器在提交按钮上未被调用。我得到404错误 login.jspJava spring mvc中未调用控制器,java,spring-mvc,Java,Spring Mvc,我是SpringMVC的初学者。我试图使用SpringMVC创建一个登录页面。但我的控制器在提交按钮上未被调用。我得到404错误 login.jsp <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html xmlns:th="http://www.w3.org/1999/xhtml" xmlns:l
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="layout/default">
<head lang="en">
<title>User Login</title>
</head>
<body>
<form method="POST" action="/SpringApplication/postLogin" >
<table>
<tr><td>User Name: </td><td><input name="userName" type="textbox"></td></tr>
<tr><td>Password: </td><td><input name="password" type="password"></td></tr>
<tr><td colspan="2" align="right"><input type="submit" value="Submit"></td></tr>
</table>
<div style="color:red">${error}</div>
</form>
</body>
</html>
dispatcher servlet.xml
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version="1.0" encoding="UTF-8"?> -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<!--
Most controllers will use the ControllerClassNameHandlerMapping above, but
for the index controller we are using ParameterizableViewController, so we must
define an explicit mapping for it.
-->
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="login.htm">indexController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!--
The index controller.
-->
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="login" />
</beans>
索引控制器
项目结构
您的按钮的动作是
action="/SpringApplication/postSearch"
当您的控制器映射时
value = "/SpringApplication/postLogin"
尝试将控制器的映射更改为
value = "/SpringApplication/postSearch"
编辑:您似乎已经解决了上述问题。但是您的控制器想要返回一个名为
“resultPage”
的jsp文件,该文件在您的jsp文件夹中找不到。您的按钮的操作是
action="/SpringApplication/postSearch"
当您的控制器映射时
value = "/SpringApplication/postLogin"
尝试将控制器的映射更改为
value = "/SpringApplication/postSearch"
编辑:您似乎已经解决了上述问题。但是您的控制器想要返回一个名为
“resultPage”
的jsp文件,该文件在您的jsp文件夹中找不到。您的表单上有一个错误的操作属性
控制器正在等待“/SpringApplication/postLogin”
请求,表单正在提交到“/SpringApplication/postSearch”
您的表单上有错误的操作属性
控制器正在等待“/SpringApplication/postLogin”
请求,表单正在提交到“/SpringApplication/postSearch”
共享视图解析器配置和jsp文件夹structure@DarkKnight,添加了请求的文件..共享viewresolver配置和jsp文件夹structure@DarkKnight,添加了请求的文件..这是一个错误@CheshireCat。。我更正了它,但它仍然不起作用。当我调试这个应用程序时,光标从未进入控制器部分。。所以我没有创建结果页(不用麻烦了)这是你唯一的控制器,还是你有一些已经在工作的控制器?是的。。这是我唯一的控制器当您的spring/bean配置可能有一些问题时。下载一本实用教程,然后对其进行更改,这可能是一个好主意。它符合您的要求。这就是我如何运行我的第一个Spring MVC项目的原因。这是一个错误@CheshireCat。。我更正了它,但它仍然不起作用。当我调试这个应用程序时,光标从未进入控制器部分。。所以我没有创建结果页(不用麻烦了)这是你唯一的控制器,还是你有一些已经在工作的控制器?是的。。这是我唯一的控制器当您的spring/bean配置可能有一些问题时。下载一本实用教程,然后对其进行更改,这可能是一个好主意。它符合您的要求。这就是我如何运行我的第一个Spring MVC项目的原因。