2016-05-12 16 views
0

私はSpring MVCで新しく、この例のように演習をしようとしています。私はindex.jspとview.jspを持っています。 Index.jspはうまくロードされていますが、load view.jspを実行すると、空のフィールドがテンティングされ、ロガーはミスを表示しません。私はIntellijIDEAを使用します。私は他の情報を与えなければならない場合、すべてのクラスやファイルの下で、私に教えてください。ありがとう。Spring MVCを使用してview.jspをロードできません

web.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
    version="3.1"> 

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

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<servlet> 
    <servlet-name>dispatcher</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>dispatcher</servlet-name> 
    <url-pattern>*.form</url-pattern> 
</servlet-mapping> 

ディスパッチャ-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" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
    http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.1.xsd 
    http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
    "> 

<context:component-scan base-package="controllers"/> 

<bean id="vievResolver" class ="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
    <property name="prefix" value="/WEB-INF/"/> 
    <property name="suffix" value=".jsp"/> 
</bean> 

<bean id="HttpGatewayInit" class ="controllers.HttpGatewayInit"> 
</bean> 

<bean name="shape" class="shapes.Rectangle"> 
    <constructor-arg index="0" value ="12" /> 
    <constructor-arg index="1" value ="2" /> 
</bean> 

<bean name="circle" class="shapes.Circle"> 
    <constructor-arg index="0" value ="8" /> 
</bean> 

<bean name="rectanglepoint" class="shapes.RectanglePoint"> 
    <constructor-arg index="0" ref ="leftend" /> 
    <constructor-arg index="1" ref ="rightend" /> 
</bean> 

<bean name="leftend" class="shapes.Point"> 
    <constructor-arg index="0" value ="4" /> 
    <constructor-arg index="1" value ="3" /> 
</bean> 

<bean name="rightend" class="shapes.Point"> 
    <property name="x" value ="12" /> 
    <property name="y" value ="8" /> 
</bean> 

コントローラ(System.out.printlnは(shape.square())私を示してい、そのマッピングは機能します)

package controllers; 

import org.springframework.asm.Attribute; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.beans.factory.annotation.Qualifier; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.WebApplicationInitializer; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.portlet.ModelAndView; 
import shapes.Shape; 

import javax.servlet.ServletContext; 
import javax.servlet.ServletException; 


@Controller 
public class MainController { 

@Autowired 
@Qualifier("shape") 
private Shape shape; 

public MainController(){ 
} 

@RequestMapping (value="/shape.form",method = RequestMethod.GET) 
public ModelAndView main(){ 
    /*class HttpGatewayInit implements WebApplicationInitializer { 
     @Override 
     public void onStartup(ServletContext servletContext) throws ServletException { 

     } 
    }*/ 

    ModelAndView modelAndView = new ModelAndView(); 
    modelAndView.setViewName("view"); 
    modelAndView.addObject("message", shape.square()); 
    System.out.println(shape.square()); 


    return modelAndView; 

} 
} 

index.jspを

<%@ page contentType="text/html;charset=UTF-8" language="java" %> 
<html> 
<head> 
    <title>$Title$</title> 
</head> 
<body> 
    <a href = "shape.form">Next page</a> 
</body> 
</html> 

view.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %> 
<html> 
<head> 
    <title>View</title> 
</head> 
<body> 
    <span>${message}</span> 
</body> 
</html> 
+0

あなたはここに私が推測する意味ですか? $ {message}に変更してください$ {message}または

$ {message}

Aditya

答えて

0

輸入

import org.springframework.web.portlet.ModelAndView; 

を確認してください、私はimport org.springframework.web.servlet.ModelAndView; にそれを変更してみました、それが私のために働きました。

+0

男、あなたは最高です!それも私のために働く。 IDEは私に2つの変種を提案しました。機械的に誤ったものを選んでいました。 – ISilchev

+0

これは私の最初の投稿stackoverflowで、私はマークする方法がわからない、それはライトの答えであり、あなたの評判を向上させる)サイトは、私は投票する15の評判を持っている必要があります私に言う。 – ISilchev

関連する問題