我正在尝试为 Spring MVC应用执行基本控制器,但 jsp文件无法识别我的变量。我正在使用基于Java的配置,之后我创建了一个用于配置的servlet.xml。
这是我的控制器:
@Controller
public class HomeController extends AbstractController{
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
ModelAndView model= new ModelAndView("home");
model.addObject("message", "Welcome to my home page!");
return model;
}
}
MyApp的-servlet的文件:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
<bean name="/jsp/home.jsp"
class="com.raulbuzila.controller.HomeController" />
我的jsp文件:
<%@ taglib prefix="c" uri="http://www.springframework.org/tags" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>RuralPrenor Homepage</title>
</head>
<body>
${message}
<a href="<c:url value="product.jsp" />">Add a product</a> |
<a href="<c:url value="register.jsp" />">Register</a>
</body>
</html>