码迷,mamicode.com
首页 > 编程语言 > 详细

Java web 常见对象的取值方法整理

时间:2014-07-14 17:38:59      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:style   java   io   div   re   c   


一、从request中取值:


1.取param:


servlet:  request.getParameter()
               request.getParameterValues()

jsp脚本:request.getParameter()

                  request.getParameterValues()

jstl/el:  ${param.name} 

             ${paramaValues.names[0]}



struts ognl:<s:property value="#parameters.ParamName[0]"/>
   


2.取attribute:


servlet: request.getAttribute();


jsp脚本:request.getAttribute();


jstl/el:${attrName}(依次查找request、session和application中的属性,找到为止)   
          ${requestScope.attrName}


struts ognl:<s:property value="#attrName">(依次查找request、session和application中的属性,找到为止)
            <s:property value="#request.attrName">


二、从servletContext(application)中取值:


1.取InitParam:


servlet: getServletContext().getInitParam("parmaName");
              getServletConfig().getServletContext.getInitParam("paramName");
     (getServletConfig().getInitParam("parmaName")和getInitParam("parmaName")是取得当前servlet中的initParam);


jsp脚本:application.getInitParam("paramName");
         config.getServletContext().getInitParam("paramName");
         config.getInitParam("paramName");


jstl/el: ${initParam.paramName}



2.取attribute:



servlet: getServletContext().getAttribute("attrName");
              getServletConfig().getServletContext.getAttribute("attrName");


jsp脚本:application.getAttribute("attrName");


jstl/el:${attrName}(依次查找request、session和application中的属性,找到为止) 
  ${applicationScope.attrName}
struts ognl:<s:property value="#attrName">(依次查找request、session和application中的属性,找到为止)
            <s:property value="#application.attrName">


三、从session中取值:


取attribute:



servlet: request.getSession().getAttribute("attrName");


jsp脚本:session.getAttribute("attrName");


jstl/el: ${attrName}(依次查找request、session和application中的属性,找到为止)
           ${sessionScope.attrName}


struts ognl:<s:property value="#attrName">(依次查找request、session和application中的属性,找到为止)
            <s:property value="#session.attrName">


四、从page中取值:


取attribute:


jsp脚本:pageContext.getAttribute(name);


jstl/el: ${pageContext.attrName}



五、从cookie中取值:


servlet: request.getCookies();


jsp脚本:request.getCookies();


jstl/el: ${cookie.cookieName.value}

Java web 常见对象的取值方法整理,布布扣,bubuko.com

Java web 常见对象的取值方法整理

标签:style   java   io   div   re   c   

原文地址:http://blog.csdn.net/shengwusuoxi/article/details/37760895

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!