Java 在我的Spring 3.2 MVC应用程序中,为什么不';登录后是否正在计算我的JSP EL表达式?
我想按照以下示例实现spring3.2.0 web mvc: 但我失败了。最后,我得到的结果是:Java 在我的Spring 3.2 MVC应用程序中,为什么不';登录后是否正在计算我的JSP EL表达式?,java,spring,model-view-controller,jsp,Java,Spring,Model View Controller,Jsp,我想按照以下示例实现spring3.2.0 web mvc: 但我失败了。最后,我得到的结果是:成功登录:${user.username},您会看到变量是无用的(JSP不工作)。我在调试中添加了一些输出,它证明@Controller、@RequestMapping工作正常。所以我不知道我的编码有什么问题 spring-servlet.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sprin
成功登录:${user.username}
,您会看到变量是无用的(JSP不工作)。我在调试中添加了一些输出,它证明@Controller、@RequestMapping工作正常。所以我不知道我的编码有什么问题
spring-servlet.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: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/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">
<context:annotation-config/>
<mvc:annotation-driven/>
<context:component-scan base-package="demo.spring"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
home.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!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=UTF-8">
<title>home</title>
</head>
<body>
Successfully logged in: ${user.username}
</body>
</html>
家
已成功登录:${user.username}
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>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>DispatchServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DispatchServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app
Web应用程序创建的原型
分发器
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/spring-servlet.xml
分发器
/
问题的可能原因是您在控制器中添加了“userForm”,并试图在JSP中以${user.username}的身份访问它
还要检查您是否在web.xml中禁用了EL表达式。我们有1000名用户依赖SpringMVC,这是迄今为止最可靠的JavaEE框架 my web.xml由maven自动生成。这是错误的
修改前(默认情况下):
修改后:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
你能发布你的web.xml吗?谢谢,我编辑了这篇文章并添加了我的web.xml。你能告诉我有什么问题吗?谢谢。我修改了我的web.xml,它现在可以工作了:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">