struts2设置index.action为主页(另:web.xml编辑卡死问题解决)

本来是弄拦截器的问题,结果弄主页的时候,还是发现了问题。

公司网站的项目里面,是用index.action作为主页的,访问WEB-INF里面的html文件。可是我设置的却不成功,追根到底,一个原因,struts2比较特殊,struts.xml里面必须多配置一个request和response。

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="3.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3_0.xsd">

    <display-name>Struts Blank</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
        
        <dispatcher>REQUEST</dispatcher> 
        <dispatcher>FORWARD</dispatcher>  
    </filter-mapping>
 

    <welcome-file-list>
        <welcome-file>index.action</welcome-file>
    </welcome-file-list>

</web-app>

这样就可以轻松使用index.action作为主页。

另外这样配置后,也可以用jsp里面加forward来跳转到index.action作为主页。也可以用html里面加一个<meta>标签刷新跳转到主页action里面。

不经过request和response,只能用html加<meta>标签的方式。

另:eclipse编辑web.xml的时候,总是卡死,是因为xml头版本的问题,里面的版本数字要一致。

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="3.0" xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3_0.xsd">

如上,都是3.0的。

原文地址:https://www.cnblogs.com/juepei/p/3755256.html