0

コントローラーからモデルを作成し、dispatcherservlet に戻ります。問題ないようですね

system.out.println による出力を再確認したため、モデルで。ビュー名文字列については、再確認しました

「WEB-INF/views/hello.jsp」である実際のディレクトリ名。

しかし、ブラウザが表示されないため、ディスパッチャーサーブレットはモデルをビューに適応させないと思います

表示すべきモデル値。自分が何を経験しているのかを理解しやすくなります

ここにコードを配置すると。そう...これが私のコードです。

web.xml

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/spring/appServlet/spring-servlet.xml
    </param-value>
</context-param>

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"
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-2.5.xsd"
>
<context:annotation-config/>
<bean name="/hello" class="com.spring.toby.HelloController"/>
<bean id="HelloSpring" class="com.spring.toby.HelloSpring"></bean>  
</beans>

およびコントローラーのJavaファイル

public class HelloController implements Controller{

@Autowired HelloSpring helloSpring;
public ModelAndView handleRequest(HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // TODO Auto-generated method stub
    String name = request.getParameter("name");
    String msg = this.helloSpring.sayHello(name);
    System.out.println(msg);
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("msg", msg);
    return new ModelAndView("WEB-INF/views/hello.jsp", model);
}
}

とビーンファイル

public class HelloSpring {
public String sayHello(String name){
    return "Hello " + name;
}
}

およびjspファイル

</head>
    <body>
    <div><h1>Testing</h1></div>
    ${message}
    </body>

誰が私が間違っているのか教えてもらえますか? 前もって感謝します。

4

1 に答える 1

1

それはただのばかげた間違いです。

jsp の${message}を${msg}に置き換えてください。メッセージが jsp に出力されます。

これがお役に立てば幸いです。

乾杯。

于 2012-05-22T06:25:06.980 に答える