CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  Web 开发

后台java代码取 request ,response ,application , session 怎么取?

楼主greki(锐╃→)2006-03-03 20:45:15 在 Java / Web 开发 提问

后台java代码取   request   ,response   ,application   ,   session   怎么取?  
  比如  
  public   class   HttpSessionBinding   implements   HttpSessionBindingListener   {  
  ...}  
  HttpSessionBinding   类里 问题点数:20、回复次数:5Top

1 楼doway(john)回复于 2006-03-03 23:02:22 得分 20

操作参数有   getSession   方法,通过   session   的   getServletContext   方法又可以获得   applicaton。  
   
  request   和   response   好像就无法获得了。  
  Top

2 楼netwar(huangls518@gmail.com)回复于 2006-03-03 23:07:27 得分 0

用HttpServlet继承吧  
   
  package   cn.com.huangls.enterprise;  
   
  import   java.io.*;  
  import   java.util.*;  
  import   java.sql.*;  
  import   javax.servlet.*;  
  import   javax.servlet.http.*;  
   
  public   class   system   extends   HttpServlet  
  {  
  private   String   sysConfigFile="config";  
  private   HttpServletRequest   request=null;  
  private   HttpServletResponse   response=null;  
   
  public   void   init(HttpServletRequest   req,HttpServletResponse   res)   throws   Exception{  
  this.request=req;  
  this.response=res;  
  }  
   
  public   String   getParaStr(String   obj,int   len,String   defaultValue){  
  String   tempValue="";  
  if(request==null)   return   "";  
  tempValue=request.getParameter(obj);  
  if(tempValue==null){  
  tempValue="";  
  }  
  tempValue=tempValue.trim();  
  if(tempValue.equals("")){  
  tempValue=defaultValue;  
  }  
  return   tempValue;  
  }  
   
  public     Connection   getConnection()   throws   Exception{  
  Connection   conn=null;  
  String   driver=getProperties("jdbc.driver");  
  String   server=getProperties("jdbc.server");  
  String   user=getProperties("jdbc.user");  
  String   password=getProperties("jdbc.password");  
   
  try{  
  Class.forName(driver);  
  }catch(Exception   ex){  
  throw   new   Exception(getProperties("error","NoFindDriver"));  
  }  
   
  try{  
  conn=DriverManager.getConnection(server,user,password);  
  }catch(Exception   ex){  
  throw   new   Exception(getProperties("error","ConnectError")+ex.toString());  
  }  
  return   conn;  
  }  
   
  public     ArrayList   executeQuery(String   strSQL)   throws   Exception{  
  ResultSet   res1=null;  
  Statement   comm=null;  
  Connection   tempConn=null;  
  ArrayList   arrayList=new   ArrayList();  
  try{  
  tempConn=getConnection();  
  if(tempConn!=null){  
  comm=tempConn.createStatement();  
  res1=comm.executeQuery(strSQL);  
  ResultSetMetaData   myStr=res1.getMetaData();  
  while(res1.next()){  
  Hashtable   b=new   Hashtable();  
  for(int   i=1;i<=myStr.getColumnCount();i++){  
  String   name=myStr.getColumnName(i);  
  String   value=res1.getString(i);  
  System.out.println(name);  
  System.out.println(value);  
  b.put(name,value);  
  }  
  arrayList.add(b);  
  }  
  }  
  }catch(Exception   ex){  
  throw   new   Exception(ex.toString());  
  }finally{  
  res1.close();  
  comm.close();  
  tempConn.close();  
  }  
  return   arrayList;  
  }  
   
  public     String   getProperties(String   field){  
  return   getProperties(sysConfigFile,field);  
  }  
   
  public     String   getProperties(String   file,String   field){  
  String   tempValue="";  
  try{  
  ResourceBundle   bundle=ResourceBundle.getBundle(file);  
  tempValue=bundle.getString(field);  
  }catch(Exception   ex){  
  System.out.println("Error:"+ex.toString());  
  }  
  return   tempValue;  
  }  
   
  //转换成中文  
  public   String   toGBK(String   tempValue){  
  String   defaultValue=tempValue;  
  try{  
  defaultValue=new   String(defaultValue.getBytes("iso8859-1"),"GBK");  
  }catch(Exception   ex){  
  System.out.println(ex.toString());  
  }  
  return   defaultValue;  
  }  
  }  
  Top

3 楼xuefeng1986(薛丰)回复于 2006-03-04 00:35:23 得分 0

想要问什么?是获得对象还是取内容?  
  取内容是这么取:  
  在servlet或者JAVA文件中可以取到前台JSP的控件中的内容   request.getParameter("控件名")  
   
  在JSP中用session.setAttribute("name","value")  
  在JAVA中用session.getAttribute("name")  
  不知道这么回答对不对?  
  Top

4 楼greki(锐╃→)回复于 2006-03-04 13:54:01 得分 0

谢谢,大家  
  通过   session   的   getServletContext   方法又可以获得   applicaton。  
  可能,request   和   response   是获得不了.  
  session超时时我想不一定有request   和   response   .  
  对这么方面理解不深...望高人指点.  
  狗年发财.:)  
  Top

5 楼xiongbing528(多情剑客无情剑)回复于 2006-03-04 20:36:16 得分 0

scope   ..scopeTop

相关问题

  • 网站的前台和后台登录Session管理问题?
  • 急问:oracle后台进程和session的问题
  • 后台编码中怎么使用Request对象?
  • 网站后台身份验证:Session+Cookie双重验证的安全性
  • 后台用Oracle
  • 关于后台..
  • 前台 后台
  • 请问后台代码中存储数组的一个session怎样在前台赋给一个javascript变量???
  • 用php做后台
  • 后台控制IE

关键词

  • null
  • tempvalue
  • getproperties
  • response
  • request
  • session
  • import
  • private

得分解答快速导航

  • 帖主:greki
  • doway

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo