eclipse学习(第二章:初识ssh)——4.struts2的配置文件

我是看着这个网址学习做的一些内容记录,方便自己以后查找。学习的话可以自己去看

https://www.w3cschool.cn/struts_2/struts_configuration.html

structs2里面的重要配置文件包括

web.xml、struts.xml、struts-config.xml以及struts.properties。

1.web.xml文件(web访问的接入点)

web.xml配置文件是一种J2EE配置文件,决定servlet容器的HTTP元素需求如何进行处理。它严格来说不是一个Struts2 配置文件,但它是Struts2 运作所需要进行配置的文件。
web.xml其实就是提供web访问的接入点,在这里面可以设置对应的过滤器。(重点:不同版本的过滤器需要配置不同的类,详情看eclipse学习(第二章:初识ssh)——3.structs2的一个demo(使用了action))
(重点)这个web.xml文件需要在WebContent/WEB-INF文件夹下创建。
如果你的工程生成并不是使用了模板或者工具辅助,那么你自己需要手动加入一个配置文件。
示例内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>ssh_learn_demo</display-name>
  
<!--   欢迎页 -->
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
<!--   过滤器 -->
  <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>
   </filter-mapping>
</web-app>

注意,我们将Struts2 过滤器映射到 /* ,而不是 /*.action ,这意味着所有的url都会被Struts过滤器解析。

2.struts.xml文件(项目配置文件,主要用于修改项目默认配置)

struts.xml文件包含有随着Actio

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值