Java Spring MVC项目中的400错误
这是我的SpringMVC项目,我正在尝试登录,但我无法登录。我已经包括了我创建的所有文件 下面是我的jsp表单Java Spring MVC项目中的400错误,java,spring,hibernate,spring-mvc,Java,Spring,Hibernate,Spring Mvc,这是我的SpringMVC项目,我正在尝试登录,但我无法登录。我已经包括了我创建的所有文件 下面是我的jsp表单 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://www.springframework.org/tags"prefix="spring"%> <%@ taglib ur
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags"prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ page session="false" %>
<html>
<head>
<title>Employee Page</title>
</head>
<body>
<form action="reg.htm" method="get">
Employee name: <input type="text" name="ename"/>
Employee ID: <input type="text" name="empno"/>
Employee job: <input type="text" name="job"/>
<input type="submit" value="success"/>
</form>
</body>
</html>
下面是我的web.xml文件
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Enables the Spring MVC @Controller programming model -->
<context:component-scan base-package="com.SpringMvcHello.Controller"/>
<bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name = "prefix" value = "/WEB-INF/jsp/" />
<property name = "suffix" value = ".jsp" />
</bean>
<bean name="e" class="com.ycs.bean.Employee"/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"></bean>
</beans>
这是我的dispatchers servlet,用于配置我的dispatchers servlet
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>HelloWorld</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Dispatcher Servlet configuration -->
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<!-- Session configuration -->
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
你好世界
index.jsp
你好
org.springframework.web.servlet.DispatcherServlet
1.
你好
*.htm
30
这是视图部分
<%@ 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>Insert title here</title>
</head>
<body>
<h1>
hello ${e.ename}</h1>
Your ID is : ${e.empno}
Your Name is : ${e.ename}
Job is : ${e.job}
</body>
</html>
在此处插入标题
你好${e.ename}
您的ID是:${e.empno}
您的名字是:${e.ename}
作业是:${e.Job}
在您的登录页面中,您有一个表单,其中包含您希望通过POST方法发送以进行评估的数据,并返回您的登录会话right
然后:
然后在索引视图中,您可以使用Spring表达式语言(SPEL)调用emp对象,如下所示:
<div>My Employee name: ${emp.ename}</div>
<form:form action="reg.htm" modelAttribute="e">
Employee name: <form:input type="text" name="ename"path="ename"/>
Employee ID: <form:input type="text" name="empno"path="empno"/>
Employee job: <form:input type="text" name="job" path="job"/>
<input type="submit" value="success"/>
</form:form>
我的员工姓名:${emp.ename}
您需要将表单更改为spring表单,如下所示:
<div>My Employee name: ${emp.ename}</div>
<form:form action="reg.htm" modelAttribute="e">
Employee name: <form:input type="text" name="ename"path="ename"/>
Employee ID: <form:input type="text" name="empno"path="empno"/>
Employee job: <form:input type="text" name="job" path="job"/>
<input type="submit" value="success"/>
</form:form>
员工姓名:
员工ID:
员工工作:
但我在您的表单中使用getWith get方法—您没有向控制器发送数据—您只是请求数据。
<form:form action="reg.htm" modelAttribute="e">
Employee name: <form:input type="text" name="ename"path="ename"/>
Employee ID: <form:input type="text" name="empno"path="empno"/>
Employee job: <form:input type="text" name="job" path="job"/>
<input type="submit" value="success"/>
</form:form>