当前位置:首页 » 网页前端 » webxmlstruts2配置
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

webxmlstruts2配置

发布时间: 2022-12-08 13:06:53

1. struts2 web.xml配置

最容易错的就是。你的struts.xml中的
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
这个部分一定要与你的struts2的版本对应的一样。建议你下载官方的包,官网
http://struts.apache.org/download.cgi#struts2181

下载truts-2.1.8.1-all.zip (110mb) [PGP] [MD5]
解压找到wapps文件。然后找到struts2-blank-2.1.8这个文件,它是一个关于struts2的空白文件,都给我们配置好了我们需要的包和一切环境。
你试一试。这个可能对你很有帮助。
看看struts.xml 如何写的

2. java web 如何加入struts2框架。

添加所需的jar包
web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
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_2_4.xsd">

<filter>
<filter-name>Struts2Filter</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>Struts2Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
还要添加一个struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<constant name="struts.custom.i18n.resources" value="actions.resources"></constant>
<package name="mystruts3" extends="struts-default" namespace="/">
<action name="" class="" method="">
<result name="" type="">result>
</action>
</package>
</struts>

3. struts2在web.xml中配置标签库有什么作用

学的j2ee的struts框架吧。If,
for
some
reason,
a
taglib
configuration
is
needed
within
web.xml,
extract
the
TLD
file
from
the
struts-core.jar
META-INF
folder,
and
add
a
taglib
element
to
the
web.xml.这是帮助文档上关于
说明,可以把一些额外的TLD文件加进来,也没说什么原因,估计是看个人喜好了
好处是方便
没必要在每个JSP页面头部导入所需的标签了,web.xml是用来初始化工程配置信息的。

4. 如何在web.xml中设置struts.xml

为什么把struts2的配置文件,引入web.xml呢

<!--定义Struts2的FilterDispatcher的Filter-->
<filter>
<!--定义核心Filter的名字-->
<filter-name>struts2</filter-name>
<!--定义核心Filter的实现类-->
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!--FilterDispatcher用来初始化Struts2并且处理所有的Web请求-->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>

这样写不就行了吗?