您的位置:首页 > 编程语言 > Java开发

Struts2中使用Servlet API步骤

2015-12-10 23:53 483 查看

Struts2中使用Servlet API步骤

  Action类中声明request等对象

    Map<String, Object> request;

  获得ActionContext实例

    ActionContext ac=ActionContext.getContext();

  获取request等对象

     request=(Map<String, Object>)ac.get("request");

  在request等对象中保存数据

     request.put("loginAccess", "登录地点是:北京");

    request.get("loginAccess");

  在页面中获取保存数据提倡的方式

    <s:property value="#request.loginAccess"/>访问Servlet API

其它方式访问Servlet API

  之前获得Servlet API对象的方式

  自己获得request: ac.get("request")

Structs2=Structs1的知名度和市场+WebWork的技术 把字符串转成OGRL表达式%{}

  自己获得session: ac.getSession()

   让“别人”为你提供Servlet API的对象

  通过实现相应接口获得Servlet API对象

  获得request需要实现RequestAware接口

  获得session需要实现SessionAware接口

  获得application需要实现ApplicationAware接口
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: