Мой проект позволяет войти в систему, а затем перейти на другую страницу, чтобы отобразить сообщение. Если данные входа неверны, отображается соответствующее сообщение об ошибке и дает им еще один шанс войти в систему. Проблема заключается в том, что сообщение, предназначенное для отображения, не является. Вместо этого все это отображается;Модель Spring MVC не отображает строку
Message is: ${message}
index.jsp
<form action="login.html" method="post">
Name: <input type="text" name="name"/>
Password: <input type="password" name="password"/>
<input type="submit" value="submit"/>
</form>
LoginController.java
package com.loginmvc.domain;
@Controller
public class LoginController {
@RequestMapping("/login")
public ModelAndView login(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String name = req.getParameter("name");
String password = req.getParameter("password");
if(password.equals("admin")) {
String message = "Welcome " + name;
return new ModelAndView("profilepage", "message", message);
} else {
return new ModelAndView("errorpage", "message",
"Sorry, the name or password is incorrect.");
}
}
}
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>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
пружинно-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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.loginmvc.domain" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
Привет, я пробовал это, но, к сожалению, он все еще не отображает строку. Самое смешное, что вчера я смог отобразить строки. – TheRealRave