allen
专注于java ee技术,包括struts,jsf,webwork,spring,hibernate,ibatis
posts - 7,  comments - 9,  trackbacks - 0


$_SERVER['PHP_SELF'] #当前正在执行脚本的文件名,与 document root相关。
$_SERVER['argv'] #传递给该脚本的参数。
$_SERVER['argc'] #包含传递给程序的命令行参数的个数(如果运行在命令行模式)。
$_SERVER['GATEWAY_INTERFACE'] #服务器使用的 CGI 规范的版本。例如,“CGI/1.1”。
$_SERVER['SERVER_NAME'] #当前运行脚本所在服务器主机的名称。
$_SERVER['SERVER_SOFTWARE'] #服务器标识的字串,在响应请求时的头部中给出。
$_SERVER['SERVER_PROTOCOL'] #请求页面时通信协议的名称和版本。例如,“HTTP/1.0”。
$_SERVER['REQUEST_METHOD'] #访问页面时的请求方法。例如:“GET”、“HEAD”,“POST”,“PUT”。
$_SERVER['QUERY_STRING'] #查询(query)的字符串。
$_SERVER['DOCUMENT_ROOT'] #当前运行脚本所在的文档根目录。在服务器配置文件中定义。
$_SERVER['HTTP_ACCEPT'] #当前请求的 Accept: 头部的内容。
$_SERVER['HTTP_ACCEPT_CHARSET'] #当前请求的 Accept-Charset: 头部的内容。例如:“iso-8859-1,*,utf-8”。
$_SERVER['HTTP_ACCEPT_ENCODING'] #当前请求的 Accept-Encoding: 头部的内容。例如:“gzip”。
$_SERVER['HTTP_ACCEPT_LANGUAGE']#当前请求的 Accept-Language: 头部的内容。例如:“en”。
$_SERVER['HTTP_CONNECTION'] #当前请求的 Connection: 头部的内容。例如:“Keep-Alive”。
$_SERVER['HTTP_HOST'] #当前请求的 Host: 头部的内容。
$_SERVER['HTTP_REFERER'] #链接到当前页面的前一页面的 URL 地址。
$_SERVER['HTTP_USER_AGENT'] #当前请求的 User_Agent: 头部的内容。
$_SERVER['HTTPS'] — 如果通过https访问,则被设为一个非空的值(on),否则返回off
$_SERVER['REMOTE_ADDR'] #正在浏览当前页面用户的 IP 地址。
$_SERVER['REMOTE_HOST'] #正在浏览当前页面用户的主机名。
$_SERVER['REMOTE_PORT'] #用户连接到服务器时所使用的端口。
$_SERVER['SCRIPT_FILENAME'] #当前执行脚本的绝对路径名。
$_SERVER['SERVER_ADMIN'] #管理员信息
$_SERVER['SERVER_PORT'] #服务器所使用的端口
$_SERVER['SERVER_SIGNATURE'] #包含服务器版本和虚拟主机名的字符串。
$_SERVER['PATH_TRANSLATED'] #当前脚本所在文件系统(不是文档根目录)的基本路径。
$_SERVER['SCRIPT_NAME'] #包含当前脚本的路径。这在页面需要指向自己时非常有用。
$_SERVER['REQUEST_URI'] #访问此页面所需的 URI。例如,“/index.html”。
$_SERVER['PHP_AUTH_USER'] #当 PHP 运行在 Apache 模块方式下,并且正在使用 HTTP 认证功能,这个变量便是用户输入的用户名。
$_SERVER['PHP_AUTH_PW'] #当 PHP 运行在 Apache 模块方式下,并且正在使用 HTTP 认证功能,这个变量便是用户输入的密码。
$_SERVER['AUTH_TYPE'] #当 PHP 运行在 Apache 模块方式下,并且正在使用 HTTP 认证功能,这个变量便是认证的类型。
posted @ 2012-02-01 12:00 robbin163 阅读(183) | 评论 (0)编辑 收藏


import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RadomCodeServlet extends HttpServlet
{

 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  doPost(request,response);
 }


 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  //设置页面不缓存
  response.setHeader("Pragma","No-cache");
  response.setHeader("Cache-Control","no-cache");
  response.setDateHeader("Expires", 0);
  //在内存中创建图象
  int width=60, height=20;
  BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

  //获取图形上下文
  Graphics g = image.getGraphics();

  //生成随机类
  Random random = new Random();

  //设定背景色
  g.setColor(getRandColor(200,250));
  g.fillRect(0, 0, width, height);

  //设定字体
  g.setFont(new Font("Times New Roman",Font.PLAIN,18));
  
  //随机产生155条干扰线,使图象中的认证码不易被其它程序探测到
  g.setColor(getRandColor(160,200));
  for (int i=0;i<155;i++)
  {
          int x = random.nextInt(width);
          int y = random.nextInt(height);
          int xl = random.nextInt(12);
          int yl = random.nextInt(12);
          g.drawLine(x,y,x+xl,y+yl);
  }
  
  //取随机产生的认证码(4位数字)
  String sRand="";
  for (int i=0;i<4;i++)
  {
      String rand=String.valueOf(random.nextInt(10));
      sRand+=rand;
      // 将认证码显示到图象中
      g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));//调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成
      g.drawString(rand,13*i+6,16);
  }

  //将认证码存入SESSION
  request.getSession().setAttribute("rand",sRand);


  //图象生效
  g.dispose();

  //输出图象到页面
  ImageIO.write(image, "JPEG", response.getOutputStream());  
 }
 
 //给定范围获得随机颜色
 private Color getRandColor(int fc,int bc)
 {
        Random random = new Random();
        if(fc>255) fc=255;
        if(bc>255) bc=255;
        int r=fc+random.nextInt(bc-fc);
        int g=fc+random.nextInt(bc-fc);
        int b=fc+random.nextInt(bc-fc);
        return new Color(r,g,b);
    }
 调用:
 <td height="25">
            <div align="right">
             <font color="#000000">验证码:</font>
            </div>
           </td>
           <td align="left">
            <input type="text" name="randCode" size=10></input>
            <img style="cursor:hand" name="validatecode"
             src=" servlet/RadomCodeServlet" height="17" align="middle"
             onclick="document.validatecode.src=' servlet/RadomCodeServlet'">
           </td>

posted @ 2006-12-08 13:51 robbin163 阅读(234) | 评论 (0)编辑 收藏
MD5

import java.security.*;


public class MD5
{
  private static MD5 md5 = null;
  private MD5(){}
  public static MD5 getInstance()
  {
    if (md5 == null)
    {
      md5 = new MD5();
    }
    return md5;
  }

  /**
   * Description:encrypt the String by "MD5"
   * @param str String
   * @return String
   */
  public String calcMD5(String str)
  {
    try
    {
      MessageDigest alga = MessageDigest.getInstance("MD5");
      alga.update(str.getBytes());
      byte[] digesta = alga.digest();
      return byte2hex(digesta);
    }
    catch (Exception e)
    {
      //System.out.println(e.getMessage());
      return null;
    }
  }

  private String byte2hex(byte[] b)
  {
    String hs = "";
    String stmp = "";
    for (int n = 0; n < b.length; n++)
    {
      stmp = (Integer.toHexString(b[n] & 0XFF));
      if (stmp.length() == 1)
      {
        hs = hs + "0" + stmp;
      }
      else
      {
        hs = hs + stmp;
      }
      if (n < b.length - 1)
      {
        hs = hs + "";
      }
    }
    return hs;
  }
}

posted @ 2006-12-08 13:49 robbin163 阅读(341) | 评论 (1)编辑 收藏

package com.jama.credentials;

import org.jasig.cas.authentication.principal.Credentials;

public class LoginInfoCredentials
    implements Credentials
{

    private String account;
    private String password;
    private String randCode;

    public LoginInfoCredentials()
    {
    }

    public String getAccount()
    {
        return account;
    }

    public void setAccount(String account)
    {
        this.account = account;
    }

    public String getPassword()
    {
        return password;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }

    public String getRandCode()
    {
        return randCode;
    }

    public void setRandCode(String randCode)
    {
        this.randCode = randCode;
    }
}


package com.jama.credentials;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jasig.cas.authentication.principal.*;

// Referenced classes of package com.jama.credentials:
//            LoginInfoCredentials

public class LoginInfoToPrincipalResolver
    implements CredentialsToPrincipalResolver
{

    private final Log log = LogFactory.getLog(getClass());

    public LoginInfoToPrincipalResolver()
    {
    }

    public Principal resolvePrincipal(Credentials credentials)
    {
        LoginInfoCredentials loginInfo = (LoginInfoCredentials)credentials;
        if(log.isDebugEnabled())
        {
            log.debug((new StringBuilder("Creating SimplePrincipal for [")).append(loginInfo.getAccount()).append("]").toString());
        }
        return new SimplePrincipal(loginInfo.getAccount());
    }

    public boolean supports(Credentials credentials)
    {
        return credentials != null && com/jama/credentials/LoginInfoCredentials.isAssignableFrom(credentials.getClass());
    }
}

posted @ 2006-12-08 13:48 robbin163 阅读(261) | 评论 (0)编辑 收藏

function ltrim(str) {
        var pattern = new RegExp("^[\\s]+","gi");
        return str.replace(pattern,"");
}

function rtrim(str) {
        var pattern = new RegExp("[\\s]+$","gi");
        return str.replace(pattern,"");
}
function trim(str) {
        return rtrim(ltrim(str));
}

posted @ 2006-11-18 14:35 robbin163 阅读(500) | 评论 (0)编辑 收藏

index.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script language="javascript">
function detect(){
  xml=new ActiveXObject("Microsoft.XMLHTTP");
  var post="";
  xml.open("POST","http://localhost:8080/xmlhttp.jsp",false);
  xml.setrequestheader("content-length" ,post.length);
  xml.setrequestheader("content-type" , "application/x-www-form-urlencoded" );
  xml.send(post);
  var res=xml.responseText;
  list.innerText=res;
  setTimeout("detect()",1000);
}
</script>

<body onload = "detect()">
test :
     <a id="list" >  </a>

</BODY>
</HTML>


xmlhttp.jsp
<%@ page language="java" contentType="text/html;charset=GB2312"%>
<%@ page import ="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<%
  Random randor=new Random();
  out.println(randor.nextInt());
%>
</BODY>
</HTML>

posted @ 2006-11-17 12:43 robbin163 阅读(172) | 评论 (0)编辑 收藏

jasperreport中可以使用List作为数据源,使用格式如下.
List list=this.customerDao.getAllCustomer();  //得到所有客户
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list);
   JasperPrint jasperPrint = JasperFillManager.fillReport(
     reportFilePath, parameters, ds);
得填充数据后,即可输出显示到PDF,Excel,Html
到PDF:
public byte[] generatePDF(String begCustNo, String endCustNo,
   String reportTitle, String reportFilePath) throws DemoException {
  // TODO Auto-generated method stub
 //begCustNo,endCustNo分别为查询传入的开始编号,结束编号.
  jdbcCustomerDao = new JdbcCustomerDao();
  Map parameters = new HashMap();
  parameters.put("ReportTitle", reportTitle);//报表标题
  List list = jdbcCustomerDao.getAllCustomer(begCustNo, endCustNo);
   try {
   JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list);
   JasperPrint jasperPrint = JasperFillManager.fillReport(
     reportFilePath, parameters, ds);   return JasperExportManager.exportReportToPdf(jasperPrint);
  } catch (JRException e) {
   throw new DemoException("Report Export Failed.");
  }
 }
到Html:
public byte[] generateHtml(String begCustNo, String endCustNo,
   String reportTitle, String reportFilePath) throws DemoException {
  jdbcCustomerDao = new JdbcCustomerDao();
  Map parameters = new HashMap();
  parameters.put("ReportTitle", reportTitle);
  List list = jdbcCustomerDao.getAllCustomer(begCustNo, endCustNo);
  System.out.println("list size is :" + list.size());
  JRHtmlExporter exporter = new JRHtmlExporter();
  ByteArrayOutputStream oStream = new ByteArrayOutputStream();
  try {
   JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list);
   JasperPrint jasperPrint = JasperFillManager.fillReport(
     reportFilePath, parameters, ds);
   exporter.setParameter(
     JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,
     Boolean.FALSE);
   exporter
     .setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
   exporter
     .setParameter(JRExporterParameter.CHARACTER_ENCODING, "GBK");
   exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, oStream);
   exporter.exportReport();
   byte[] bytes = oStream.toByteArray();
   return bytes;
  } catch (JRException e) {
   throw new DemoException("Report Export Failed.");
  }
 }
到Excel:
public byte[] generateExcel(String begCustNo, String endCustNo,
   String reportTitle, String reportFilePath) throws DemoException {
  jdbcCustomerDao = new JdbcCustomerDao();
  Map parameters = new HashMap();
  parameters.put("ReportTitle", reportTitle);
  List list = jdbcCustomerDao.getAllCustomer(begCustNo, endCustNo);
  System.out.println("list size is :" + list.size());
  JRXlsExporter exporter = new JRXlsExporter(); // Excel
  ByteArrayOutputStream oStream = new ByteArrayOutputStream();
  try {
   JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(list);
   JasperPrint jasperPrint = JasperFillManager.fillReport(
     reportFilePath, parameters, ds);
   exporter
     .setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
   exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, oStream);
   exporter.setParameter(
     JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
     Boolean.TRUE);
   exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,
     Boolean.FALSE);
   exporter.setParameter(
     JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND,
     Boolean.FALSE);
   exporter.exportReport();
   byte[] bytes = oStream.toByteArray();
   return bytes;

  } catch (JRException e) {
   throw new DemoException("Report Export Failed.");
  }
 }

jsp调用方法:
 <%
    
   
 String filePath=getServletContext().getRealPath("/")+"report.jasper"; 

 CustomerServiceImpl  custs=new CustomerServiceImpl();
    byte[] bytes=null;
  String begNo=request.getParameter("beginCustNo");
  String endNo=request.getParameter("endCustNo");
  String type=request.getParameter("type");

  if(type.equals("Pdf")){ 
      bytes= custs.generatePDF(begNo,endNo,"客户资料明细表",filePath);
  }else if(type.equals("Excel")){
   bytes=custs.generateExcel(begNo,endNo,"客户资料明细表",filePath);
  }else
     bytes=custs.generateHtml(begNo,endNo,"客户资料明细表",filePath);


 if(bytes!=null){
  if(type.equals("Pdf")){
         response.setContentType("application/pdf");
  }else if(type.equals("Excel")){
     response.setContentType("application/vnd.ms-excel");
  }else
   response.setContentType("text/html");
    response.setContentLength(bytes.length);
    ServletOutputStream ouputStream = response.getOutputStream();
    ouputStream.write(bytes,0,bytes.length);
    ouputStream.flush();
    ouputStream.close();
 }else
 {
  out.println("error");
 }
 

 

  %>

posted @ 2006-11-12 22:21 robbin163 阅读(6351) | 评论 (6)编辑 收藏
仅列出标题  

<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(3)

随笔分类

随笔档案

文章分类

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜