내 프로젝트는 최종 사용자가 로그인 한 다음 다른 페이지로 이동하여 메시지를 표시하는 프로젝트입니다. 로그인 세부 사항이 틀리면 적절한 오류 메시지를 표시하고 다시 로그인 할 수있는 기회를줍니다. 문제는 표시 할 메시지가 아니라는 것입니다. 대신 표시되는 것은 모두입니다.봄 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에
,174,<?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