當前位置:首頁 » 網頁前端 » 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>

這樣寫不就行了嗎?