Я начинаю с Spring Web MVC.У меня очень простой контроллер и вид, но когда я открываю страницу http://localhost:8080/springonly/spring/hello, я получаю: ${message}
, а не Hello World
Кто-нибудь знает, что с этим не так?Почему $
-выражение не было распознано?
Просмотр - hello.jsp
:
${message}
Контроллер - HelloController.java
:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloController {
@RequestMapping("/hello")
public ModelAndView hello(HttpServletRequest request,
HttpServletResponse response) throws Exception {
return new ModelAndView("hello", "message", "Hello World");
}
}
web.xml
:
<web-app>
<display-name>Spring Only WebApp</display-name>
<servlet>
<servlet-name>springonly</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springonly</servlet-name>
<url-pattern>/spring/*</url-pattern>
</servlet-mapping>
</web-app>
applicationContext.xml
:
<!-- scan for Controllers -->
<context:component-scan base-package="net.marioosh.spring.springonly" />
<!-- view resolver -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
log сказать:
2011-03-15 13:43:12,703 DEBUG [DispatcherServlet:693] : DispatcherServlet with name 'springonly' processing GET request for [/springonly/spring/hello]
2011-03-15 13:43:12,718 DEBUG [DefaultAnnotationHandlerMapping:221] : Mapping [/hello] to HandlerExecutionChain with handler [net.marioosh.spring.springonly.HelloController@120b2da] and 1 interceptor
2011-03-15 13:43:12,718 DEBUG [DispatcherServlet:769] : Last-Modified value for [/springonly/spring/hello] is: -1
2011-03-15 13:43:12,718 DEBUG [HandlerMethodInvoker:173] : Invoking request handler method: public org.springframework.web.servlet.ModelAndView net.marioosh.spring.springonly.HelloController.hello(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.lang.Exception
2011-03-15 13:43:12,718 DEBUG [DispatcherServlet:1045] : Rendering view [org.springframework.web.servlet.view.JstlView: name 'hello'; URL [/WEB-INF/pages/hello.jsp]] in DispatcherServlet with name 'springonly'
2011-03-15 13:43:12,718 DEBUG [JstlView:328] : Added model object 'message' of type [java.lang.String] to request in view with name 'hello'
2011-03-15 13:43:12,718 DEBUG [JstlView:236] : Forwarding to resource [/WEB-INF/pages/hello.jsp] in InternalResourceView 'hello'
2011-03-15 13:43:12,718 DEBUG [DispatcherServlet:674] : Successfully completed request