コントローラークラスは次のようになります。
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class MainController {
@RequestMapping(value = "/chart", method = RequestMethod.GET)
public ModelAndView helloWorld() {
System.out.println("Controller accessed...");
String message = "<br><div style='text-align:center;'> CONTROLLER ACCESSED</div><br><br>";
return new ModelAndView("chart", "hello", message);
}
}
「chart.jsp」という名前の私のjspファイルは次のようになります
<html>
<head>
<title>Spring MVC - Chart
Example</title>
</head>
<body>${hello}
<br>
<br>
<div style="font-family: verdana; padding: 10px; border-radius: 10px; font-size: 12px; text-align:center;">
Insert Chart here. ${hello}<br>
</div>
</body>
</html>
私の問題は、.jsp ファイルの両方の "${hello}" が、index.jsp で指定した文字列ではなく、"${hello}" のままであることです。
また、println がコンソールに正常に出力されるため、コントローラーにアクセスします。
追加: 問題の原因である可能性があるため、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>
<display-name>Web Application</display-name>
<!-- Processes application requests -->
<!-- <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context.xml</param-value>
</context-param> -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/chart.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/chart.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>