我有一个使用Spring的maven项目,目前我的索引页已启动并运行在Tomcat上。在我的索引页,我有:Spring MVC。请求映射不起作用。 index.jsp的链接不加载。
<a href="about">about</a>
然后在WEB-INF文件夹,我有一个子文件夹名为JSP,其中包括about.jsp。我陷入了如何让href作为网页打开about.jsp。我试着创建一个控制器类,但我不确定是否正确地做了。我所有的控制器都是,
@Controller
public class AboutController {
@RequestMapping("/about")
public ModelAndView helloWorld() {
String message = "Hello World";
return new ModelAndView("about", "message", message);
}
}
web.xml中的servlet映射看起来像。
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
然后用SpringMVC我-servlet.xml中
<context:component-scan base-package="com.springMVC.controller" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" />
<mvc:annotation-driven />
我已经尝试了一些不同的教程,但他们都没有奏效。
我还要指出,如果我启动Tomcat和去为localhost:8080 /测试/ about.jsp它的作品,我只是不能链接工作。
看一下View Resolver。 http://www.baeldung.com/spring-mvc-view-resolver-tutorial –