濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > Struts2訪問(wèn)servlet分享

Struts2訪問(wèn)servlet分享

熱門(mén)標(biāo)簽:智能電話(huà)機(jī)器人銷(xiāo)售話(huà)術(shù) 福建電銷(xiāo)貓機(jī)器人收費(fèi) 地圖標(biāo)注專(zhuān)業(yè)和非專(zhuān)業(yè) 汝南縣地圖標(biāo)注app 山東ai外呼電銷(xiāo)機(jī)器人好用嗎 湖北地圖標(biāo)注公司 四川正規(guī)外呼系統(tǒng)軟件 甘肅銷(xiāo)售電銷(xiāo)機(jī)器人公司 外呼直播語(yǔ)音系統(tǒng)

一:訪問(wèn)或添加request/session/application屬性
 

復(fù)制代碼 代碼如下:

public String scope() throws Exception{

   ActionContext ctx = ActionContext.getContext();

   ctx.getApplication().put("app", "應(yīng)用范圍");//往ServletContext里放入app

   ctx.getSession().put("ses", "session范圍");//往session里放入ses

   ctx.put("req", "request范圍");//往request里放入req

   return "scope";

}


 

JSP:

復(fù)制代碼 代碼如下:

 body>

    ${applicationScope.app} br>

    ${sessionScope.ses}br>

    ${requestScope.req}br>

 /body>


 

二:獲取HttpServletRequest / HttpSession / ServletContext / HttpServletResponse對(duì)象
 

方法一,通過(guò)ServletActionContext.類(lèi)直接獲取:

復(fù)制代碼 代碼如下:

public String rsa() throws Exception{

       HttpServletRequest request = ServletActionContext.getRequest();

       ServletContext servletContext = ServletActionContext.getServletContext();

       request.getSession()

       HttpServletResponse response = ServletActionContext.getResponse();

       return "scope";

}


方法二,實(shí)現(xiàn)指定接口,由struts框架運(yùn)行時(shí)注入:
復(fù)制代碼 代碼如下:

public class HelloWorldAction implements ServletRequestAware, ServletResponseAware, ServletContextAware{

       private HttpServletRequest request;

       private ServletContext servletContext;

       private HttpServletResponse response;

       public void setServletRequest(HttpServletRequest req) {

              this.request=req;

       }

       public void setServletResponse(HttpServletResponse res) {

              this.response=res;

       }

       public void setServletContext(ServletContext ser) {

              this.servletContext=ser;

       }

}

您可能感興趣的文章:
  • 詳談Servlet和Filter的區(qū)別以及兩者在Struts2和Springmvc中的應(yīng)用
  • 詳解Struts2中Action訪問(wèn)Servlet API的幾種方法
  • Struts2訪問(wèn)Servlet的三種方式
  • Struts和servlet不能共存問(wèn)題解決方法

標(biāo)簽:吳忠 白銀 梅州 昌都 臨沂 南充 肇慶 黔東

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Struts2訪問(wèn)servlet分享》,本文關(guān)鍵詞  Struts2,訪問(wèn),servlet,分享,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Struts2訪問(wèn)servlet分享》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于Struts2訪問(wèn)servlet分享的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    新竹县| 赤水市| 青阳县| 鸡西市| 岢岚县| 临潭县| 乌恰县| 宣化县| 安康市| 汝阳县| 寻甸| 阳高县| 博白县| 丰原市| 哈尔滨市| 石门县| 贵德县| 栾城县| 车致| 雷山县| 永丰县| 白玉县| 共和县| 拜城县| 惠安县| 栖霞市| 古交市| 阿克苏市| 泾源县| 大英县| 阜平县| 二连浩特市| 巫溪县| 中卫市| 襄垣县| 都匀市| 维西| 英吉沙县| 介休市| 大名县| 西城区|