1.先访问jsp文件,在从jsp访问contorller层
第一步:
访问jsp给mvc中配置默认视图
添加如下:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 这里的配置我的理解是自动给后面action的方法return的字符串加上前缀和后缀,变成一个 可用的url地址 -->
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
第二步:
在web.xml中添加如下
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>xxxx/xxxx/xxxx.jsp</welcome-file>
</welcome-file-list>
第三步:
在jsp中自己编译跳转路径
2.直接访问contorller层,在跳转jsp页面
方法1:在controller类和该类方法上注解路径(“/”)
@Controller
@RequestMapping("/")
public class index {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(Model model){
return "index";
}
}
web.xml文件配置
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
方法2
controller类照常配置
配置web.xml时把下方内容删除
<!--<welcome-file-list>-->
<!--<!–<welcome-file>/WEB-INF/jsp/index.jsp</welcome-file>–>-->
<!--<welcome-file>/user/weChat</welcome-file>-->
<!--</welcome-file-list>-->
方法3
在mvc配置文件中配置
<!-- 定义无Controller的path<->view直接映射 -->
<mvc:view-controller path="/" view-name="redirect:login" />
在web.xml配置文件中配置
<welcome-file-list>
<welcome-file>login</welcome-file>
</welcome-file-list>
如果进行微信测试用此框架,启动项目后 打开网站报404 属于正常,正常使用微信接口就行