配置welcome-file-list跳转

本文介绍了一种在web.xml文件中通过<welcome-file>标签设置默认欢迎页面并利用HTML的meta标签实现自动刷新重定向的方法。具体做法是在index.html中加入<meta http-equiv='refresh' content='0;url=index.action'>,从而实现访问首页时直接跳转到index.action。
web.xml里是

<welcome-file>index.html</welcome-file>

index.html内容:
<meta http-equiv='refresh' content='0;url=index.action'>
,这样当访问index.html的时候立即跳转到index.action里。
package com.buka.controller; import com.buka.po.Clazz; import com.buka.service.ClassService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; import java.util.List; @Controller public class ClassController { @Autowired ClassService classService; @RequestMapping("/menu") public ModelAndView index(Clazz classes , ModelAndView mv) { List<Clazz> classList=classService.selClass(new Clazz()); mv.addObject("classist",classList); mv.setViewName("menu.jsp"); return mv; } @RequestMapping("/addClass") public ModelAndView addClass(Clazz clazz,ModelAndView mv){ classService.addClass(clazz); mv.addObject("clazz",clazz); List<Clazz> classList=classService.selClass(clazz); mv.addObject("classist",classList); mv.setViewName("index.jsp"); return mv; } } <%@ page contentType="text/html;charset=UTF-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>班级列表</title> </head> <body> <h3>班级列表</h3> <a href="addClass.jsp">添加班级</a> <table border="1"> <tr> <th>班级名称</th> <th>操作</th> </tr> <c:forEach var="cls" items="${classist}"> <tr> <td>${cls.cname} (ID: ${cls.cid})</td> <td> <button>查看成绩</button> <a href="Student.jsp?classId=${cls.cid}">查看学生</a> </td> </tr> </c:forEach> </table> </body> </html><?xml version="1.0" encoding="UTF-8"?> <web-app version="4.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:javaee="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"> <display-name>Archetype Created Web Application</display-name> <welcome-file-list> <welcome-file>menu.jsp</welcome-file> </welcome-file-list> <!-- SpringMVC--> <servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc-config.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- 配置Spring的监听器,用于加载Spring配置文件 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:application.xml</param-value> </context-param> <filter> <filter-name>charset</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>charset</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> 为什么我添加了welcome后还是不能直接访问到带有班级信息的menu.jsp文件
最新发布
09-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值