2016-07-01 12 views
1

私のプロジェクトはエンドユーザーのログインを許可し、別のページに移動してメッセージを表示することです。ログインの詳細が間違っていると、適切なエラーメッセージが表示され、ログインする別の機会が与えられます。問題は、表示されるメッセージが正しくないことです。代わりに表示されているのはすべてです。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> 

答えて

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> 

を、私はあなたが新しいものを見つけることをお勧めします。しかし、その間に、あなたの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" 
     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

あなたが使用していることを確認してください:このTaglibのあなたのJSP

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

とメッセージ印刷するには:<c:if test="${not empty message}">${message}</c:if>

eclipseやnetbeansのようなIDEを使用することをお勧めします。これにより、JSPLでtaglibエラーや警告を検出するのが簡単になります。

関連する問題