java 九大内置对象

阅读: 评论:0

java 九大内置对象

java 九大内置对象

jsp九大内置对象包括request response session application out page config exception pageContent

其中 request  response  out page config exception pageContent对象的有效范围是当前页面的应用  session 有效范围是当前会话(当前客户端的所有页面) application 有效范围是整个应用程序,只要服务器不关闭对象就有效

====================================================================

request

====================================================================

request.setCharacterEncoding("UTF-8");设置请求编码,防止乱码

request.setAttribute("Unmae", new Object());将数据保存到request范围内的变量中

request.forward(String Url);转发

====================================================================

cookie

====================================================================

URLEncoder.decode();读取cookie信息时将信息解码

====================================================================

response

====================================================================

response.addCookie()将一个cookie对象发送到客户端

response.sendRedirect(String path); 重定向

====================================================================

application

====================================================================

application.setAttribute(key,value);给application添加属性值

====================================================================

session

====================================================================

session.setMaxInactiveInterval(int num);设置session对象的有效活动时间

session.isNew();判断是否为新用户  返回Boolean

session.setAttribute();

session.invalidate();销毁当前session

====================================================================

案例

====================================================================

1:防止表单在网站外部提交  使用request

String address&#RequestURL().toString();//获得当前的IE地址

String addresstwo&#Header("referer");//获得请求地址

String pathadd=null;//当前服务器主机

String pathaddtwo=null;//访问服务器主机

//获得访问主机名称

try {

if(address!=null&&address!=""){

URL url=new URL(address);

pathadd&#Host();

}

if(addresstwo!=null&&addresstwo!=""){

URL url1=new URL(addresstwo);

pathaddtwo&#Host();

}

if(pathadd.equals(pathaddtwo)){

}else{

}

} catch (MalformedURLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

2:网站计数器  application

synchronized  java关键字  使用中一个线程未完成锁定下一个线程

int i=0;

synchronized (application) {

Attribute("times")==null){//服务器启动后的第一位访问者

i=1;

}else{

i=Integer.Attribute("times"));

i++;//访问次数加一

}

application.setAttribute("times",String(i)); //将访问次数存入到application中

}

====================================================================

本文发布于:2024-01-31 01:06:39,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170663440024230.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:九大   对象   java
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23