预览模式: 普通 | 列表

从URL获取文件保存到本地的代码

<%@page import="java.net.*,java.io.*"%>
<%!
public boolean saveUrlAs(String photoUrl, String fileName) {
//此方法只能用户HTTP协议
try {
URL url = new URL(photoUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
DataInputStream in = new DataInputStream(connection.getInputStream());
DataOutputStream out = new DataOutputStream(new FileOutputStream(fileName));
byte[] buffer = new byte[4096];
int count = 0;
while ((count = in.read(buffer)) > 0) {

查看更多...

分类:JSP | 固定链接 | 评论: 0 | 人气: 730℃

JSP日期随机数

<%
Date Today = new Date();
int NowYear = Today.getYear() + 1900;
int NowMonth = Today.getMonth() + 1;
int NowDate = Today.getDate();
int NowHour = Today.getHours();
int NowMinute = Today.getMinutes();
int NowSecond = Today.getSeconds();
String StrMonth,StrDate,StrHour,StrMinute,StrSecond;
if (NowMonth < 10){StrMonth = "0" + NowMonth;}else{StrMonth = "" + NowMonth;}
if (NowDate < 10){StrDate = "0" + NowDate;}else{StrDate = "" + NowDate;}

查看更多...

分类:JSP | 固定链接 | 评论: 0 | 人气: 960℃

JSP验证码

<%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %>
<%!
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);
}
%>
<%
//设置页面不缓存
response.setHeader("Pragma","No-cache");

查看更多...

分类:JSP | 固定链接 | 评论: 0 | 人气: 943℃

JSP连接ACCESS、SQL 2000 数据库

<% 
/*
JSP连接ACCESS、SQL 2000 数据库
Create By 2006-2-3
Power by Love_Computer...
http://www.56390.com/
*/

int strDB = 1;
String DB_Server,DB_Name,User_DB,Password_DB,strClass,Url_DB,strSQL;
if (strDB == 0)
{
//SQL
DB_Server = "127.0.0.1";
DB_Name = "pubs";
User_DB = "sa";
Password_DB = "";
strClass = "com.microsoft.jdbc.sqlserver.SQLServerDriver";

查看更多...

分类:JSP | 固定链接 | 评论: 0 | 人气: 956℃