2016-07-01 4 views
1

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

답변

1

web.xml 파일에 이전 설명자를 사용하고 있습니다. 는 EL 발생합니다이를 무시 : 당신이 자습서를 다음과 같은 경우

<!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> 

, 나는 당신이 새로운 하나를 발견하는 것이 좋습니다 것입니다. 당신의 JSP

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

이 태그 라이브러리와 메시지를 인쇄하려면 :

<?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" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     version="3.0"> 
... 
</web-app> 
+0

안녕하세요,이 시도했지만 불행히도 여전히 문자열을 표시하지 않습니다. 웃기는 것은 어제 문자열을 표시 할 수 있었다는 것입니다. – TheRealRave

0

것은 당신이 사용하고 있는지 확인 그러나, 그 동안, 당신의 web.xml를 업데이트하면 즉시 문제를 해결해야 <c:if test="${not empty message}">${message}</c:if>

eclipse 또는 netbeans와 같은 IDE를 사용하여 jsp에서 taglib 오류 및 경고를 쉽게 감지 할 수 있도록하는 것이 좋습니다.

관련 문제