Struts2学习第三课 Struts2详解
生活随笔
收集整理的這篇文章主要介紹了
Struts2学习第三课 Struts2详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
接著上次的課程
這次我們看struts.xml
修改如下:這里是加上命名空間,默認的是不加,我們手動加上時就要在訪問時加上命名空間。
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts><!-- package:包,struts2使用package來組織模塊name屬性:必須,用于其他包引用當前包extends: 當前包繼承哪個包,繼承的,即可以繼承其中的所有的配置,通常情況下繼承struts-defaultstruts-default這個包在struts-default.xml文件中定義的--><package name="helloWorld" extends="struts-default" namespace="/logan"><!-- 配置action:一個struts2的請求就是一個actionname:對應一個Struts2的請求的名字,不包含擴展名 --><action name="product-input"><result>/WEB-INF/pages/input.jsp</result></action><action name="product-save" class="logan.struts.study.Product" method="save"><result name="details">/WEB-INF/pages/details.jsp</result></action></package></struts>我們再去訪問地址http://localhost:8080/Struts2-2/product-input.action
可以看到訪問失敗
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [product-input] associated with context path [/Struts2-2].type Status reportmessage There is no Action mapped for namespace [/] and action name [product-input] associated with context path [/Struts2-2].description The requested resource is not available.Apache Tomcat/9.0.0.M15我們訪問這個地址才能訪問:http://localhost:8080/Struts2-2/logan/product-input.action
action里面class的默認值是com.opensymphony.xwork2.ActionSupport
默認的執行方法時execute
result:結果,表示action方法執行后可能返回的一個結果。所以一個action節點可能會有多個result子節點。多個result子節點使用name來區分。
name:標識一個result,和cation方法的返回值對應,的默認值是success。
type:表示結果的類型,默認值為dispatcher(轉發到結果)
?
轉載于:https://www.cnblogs.com/LoganChen/p/6942304.html
總結
以上是生活随笔為你收集整理的Struts2学习第三课 Struts2详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python程序,辅助微信跳一跳游戏介绍
- 下一篇: SybaseASE系统表的应用