struts

来源:互联网 发布:求欧美复古风淘宝店铺 编辑:程序博客网 时间:2024/06/07 18:13

获取用户输入

  1. 使用领域对象接收用户输入(user.username)需要set、get
  2. 实现ModelDriven 的action,实现getModel (直接使用领域对象 username)不需set,get。
  3. 使用action的属性接收用户输入

访问request、session和application对象

  • 与servlet API解耦的方式访问
直接使用HttpServletRequest、HttpSession和ServletContext对应的Map对象来保存和读取数据
要获取这三个Map对象,使用ActionContext类    ActionContext.getContext()
get(“request”)
getSession()
getApplication()
在JSP页面,${sessionScope.} ${requestScope.},${applicationScope.}
也可以实现某些特定的接口  RequestAware,SessionAware,ApplicationAware

  • 与servlet API耦合的访问方式
ServletActionContext类(继承于ActionContext)的静态方法
HttpServletRequest getRequest()  此对象可以得到HttpSession
ServletContext getServletContext()
HttpServletResponse getResponse()
还可以ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST)
<pre name="code" class="html">ActionContext.getContext().get(ServletActionContext.SERVLET_CONTEXT)
ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE)

还可以实现ServletRequestAware,ServletContextAware,




0 0