新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

关于多段图java代码的信息

哪位大侠可以帮我写一段java代码!是关于根据数据库里的数据来形成一个动态树形图

这是代码,你可以自己调试一下。

10年积累的成都做网站、网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站策划后付款的网站建设流程,更有龙泉免费网站建设让你可以放心的选择与我们合作。

数据结构如下:

CREATE TABLE dtree (

id int,

pid int,

name varchar(200),

url varchar(200),

title varchar(200),

target varchar(200),

icon varchar(200),

iconopen varchar(200),

opened bit);

为了实现获取数据库变量功能,需要建立一个DTree类,并编译生成CLASS文件,放入\WEB-INF\classes文件夹下。

DTree类代码如下:

package work3;

public class DTree {

private int id;

private int pid;

private String name;

private String url;

private String title;

private String target;

private String icon;

private String iconOpen;

private int opened;

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public int getPid() {

return pid;

}

public void setPid(int pid) {

this.pid = pid;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getUrl() {

return url;

}

public void setUrl(String url) {

this.url = url;

}

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

public String getTarget() {

return target;

}

public void setTarget(String target) {

this.target = target;

}

public String getIcon() {

return icon;

}

public void setIcon(String icon) {

this.icon = icon;

}

public String getIconOpen() {

return iconOpen;

}

public void setIconOpen(String iconOpen) {

this.iconOpen = iconOpen;

}

public int getOpened() {

return opened;

}

public void setOpened(int opened) {

this.opened = opened;

}

}

work3.jsp代码如下:

%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%

%@ page import="java.sql.*"%

jsp:useBean id='settree' scope="application" class="work3.DTree" /

!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

""

html

head

meta http-equiv="Content-Type" content="text/html; charset=GB18030"

link rel="StyleSheet" href="dtree.css" type="text/css" /

script type="text/javascript" src="dtree.js"/script

titledTree in MySQL/title

/head

body

h2

Example

/h2

div class="dtree"

p

a href="javascript: d.openAll();"open all/a |

a href="javascript: d.closeAll();"close all/a

/p

script type="text/javascript"

!--

d = new dTree('d');

%

//驱动程序名

String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";

//数据库用户名

String userName = "sa";

//密码

String userPwd = "1";

//数据库名

String dbName = "master";

//表名

String tableName = "dtree";

//连接字符串

String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName="+dbName;

//加载驱动

Class.forName(driverName).newInstance();

//连接数据库

java.sql.Connection conn = DriverManager.getConnection(url,userName,userPwd);

//得到Statement实例

java.sql.Statement statement = conn.createStatement();

//查询数据

String sql = "select * from " + tableName;

//返回结果

java.sql.ResultSet rs = statement.executeQuery(sql);

//获取变量

while (rs.next()) {

settree.setId(rs.getInt(1));

settree.setPid(rs.getInt(2));

settree.setName(rs.getString(3));

settree.setUrl(rs.getString(4));

settree.setTitle(rs.getString(5));

settree.setTarget(rs.getString(6));

settree.setIcon(rs.getString(7));

settree.setIconOpen(rs.getString(8));

settree.setOpened(rs.getInt(9));

if(settree.getPid()==0)

settree.setOpened(1);

%

d.add(%=settree.getId()%,%=settree.getPid()%,'%=settree.getName()%','%=settree.getUrl()%','%=settree.getTitle()%','%=settree.getTarget()%','','',%=settree.getOpened()%);

%

}

%

document.write(d);

//--

/script

/div

/body

/html

用java完成图片多张批量上传的功能,还有就是后台的应该怎么处理上传的照片。

环境准备

1. 下载并安装Tomcat(已经有很多关于Tomcat安装以及使用的文章,在这里不再介绍);

2. 下载File upload的jar包commons-fileupload-1.0-beta-1.jar,并将该文件拷贝到{$TOMCAT}/common/lib目录下(其中{$TOMCAT}为Tomcat的安装目录);

3. 由于Fileupload子项目同时要用到另外一个项目commons-Beanutils,所以必须下载Beanutils,并将解压后的文件commons-beanutils.jar拷贝到{$TOMCAT}/common/lib目录下。

开发文件上传页面

文件上传的界面如图1所示。为了增加效率我们设计了三个文件域,同时上传三个文件。

图1 文件上传界面

页面的HTML代码如下:

html

head

title文件上传演示/title

/head

body bgcolor=“#FFFFFF”text=“#000000” leftmargin=“0”topmargin=“40”marginwidth=“0” marginheight=“0”

center

h1文件上传演示/h1

form name=“uploadform”method=“POST” action=“save.jsp”ENCTYPE=“multipart/form-data”

table border=“1”width=“450”cellpadding=“4” cellspacing=“2”bordercolor=“#9BD7FF”

trtd width=“100%”colspan=“2”

文件1:input name=“file1”size=“40”type=“file”

/td/tr

trtd width=“100%”colspan=“2”

文件2:input name=“file2”size=“40”type=“file”

/td/tr

trtd width=“100%”colspan=“2”

文件3:input name=“file3”size=“40”type=“file”

/td/tr

/table

br/br/

table

trtd align=“center”input name=“upload” type=“submit”value=“开始上传”//td/tr

/table

/form

/center

/body

/html

代码中要特别注意的是黑体处。必须保证表单的ENCTYPE属性值为multipart/form-data,这样浏览器才能正确执行上传文件的操作。

处理上传文件信息

由于本文主要是讲述如何使用Commons-fileupload,所以为了便于修改、调试,上传文件的保存使用一个JSP文件来进行处理。我们将浏览器上传来的所有文件保存在一个指定目录下并在页面上显示所有上传文件的详细信息。保存页面处理结果见图2所示。

图2 保存页面

下面来看看save.jsp的代码:

%

/**

* 演示文件上传的处理

* @author a href=“mailto:winter.lau@163.com”Winter Lau/a

* @version $Id: save.jsp,v 1.00 2003/03/01 10:10:15

*/

%

%@ page language=“java”contentType=“text/html;charset=GBK”%

%@ page import=“java.util.*”%

%@ page import=“org.apache.commons.fileupload.*”%

html

head

title保存上传文件/title

/head

%

String msg = “”;

FileUpload fu = new FileUpload();

// 设置允许用户上传文件大小,单位:字节

fu.setSizeMax(10000000);

// maximum size that will be stored in memory?

// 设置最多只允许在内存中存储的数据,单位:字节

fu.setSizeThreshold(4096);

// 设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录

fu.setRepositoryPath(“C:\\TEMP”);

//开始读取上传信息

List fileItems = fu.parseRequest(request);

%

body bgcolor=“#FFFFFF”text=“#000000” leftmargin=“0”topmargin=“40”marginwidth=“0” marginheight=“0”

font size=“6”color=“blue”文件列表:/font

center

table cellpadding=0 cellspacing=1 border=1 width=“100%”

tr

td bgcolor=“#008080”文件名/td

td bgcolor=“#008080”大小/td

/tr

%

// 依次处理每个上传的文件

Iterator iter = fileItems.iterator();

while (iter.hasNext()) {

FileItem item = (FileItem) iter.next();

//忽略其他不是文件域的所有表单信息

if (!item.isFormField()) {

String name = item.getName();

long size = item.getSize();

if((name==null||name.equals(“”)) size==0)

continue;

%

tr

td%=item.getName()%/td

td%=item.getSize()%/td

/tr

%

//保存上传的文件到指定的目录

name = name.replace(‘:’,‘_’);

name = name.replace(‘\\’,‘_’);

item.write(“F:\\”+ name);

}

}

%

/table

br/br/

a href=“upload.html”返回上传页面/a

/center

/body

/html

在这个文件中需要注意的是FileUpload对象的一些参数值的意义,如下面代码所示的三个参数sizeMax、sizeThreshold、repositoryPath:

FileUpload fu = new FileUpload();

// 设置允许用户上传文件大小,单位:字节

fu.setSizeMax(10000000);

// maximum size that will be stored in memory?

// 设置最多只允许在内存中存储的数据,单位:字节

fu.setSizeThreshold(4096);

// 设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录

fu.setRepositoryPath(“C:\\TEMP”);

这3个参数的意义分别为:

SizeMax 用来设置上传文件大小的最大值,一旦用户上传的文件大小超过该值时将会抛出一个FileUploadException异常,提示文件太大;

SizeThreshold 设置内存中缓冲区的大小,一旦文件的大小超过该值的时候,程序会自动将其它数据存放在repositoryPath指定的目录下作为缓冲。合理设置该参数的值可以保证服务器稳定高效的运行;

RepositoryPath 指定缓冲区目录。

使用注意事项

从实际应用的结果来看该模块能够稳定高效的工作。其中参数SizeThreshold的值至关重要,设置太大会占用过多的内存,设置太小会频繁使用硬盘作为缓冲以致牺牲性能。因此,设置该值时要根据用户上传文件大小分布情况来设定。例如大部分文件大小集中在100KB左右,则可以使用100KB作为该参数的值,当然了再大就不合适了。使用commons-fileupload来处理HTTP文件上传的功能模块很小,但是值得研究的东西很多。

求一段java代码,要求如下

你这个功能还是很简单的 百度找找就有了。代码我就懒得写了 反正不复杂

这段JAVA代码什么意思

javax.crypto.Cipher类提供加密和解密功能,该类是JCE框架的核心。

一,与所有的引擎类一样,可以通过调用Cipher类中的getInstance静态工厂方法得到Cipher对象。

public static Cipher getInstance(String transformation);

public static Cipher getInstance(String transformation,String provider);

参数transformation是一个字符串,它描述了由指定输入产生输出所进行的操作或操作集合。

参数transformation总是包含密码学算法名称,比如DES,也可以在后面包含模式和填充方式。

参数transformation可以是下列两种形式之一:

“algorithm/mode/padding”

“algorithm”

例如下面的例子就是有效的transformation形式:

"DES/CBC/PKCS5Padding"

"DES"

如 果没有指定模式或填充方式,就使用特定提供者指定的默认模式或默认填充方式。例如,SunJCE提供者使用ECB作为DES、DES-EDE和 Blowfish等Cipher的默认模式,并使用PKCS5Padding作为它们默认的填充方案。这意味着在SunJCE提供者中,下列形式的声明是 等价的:Cipher c1=Cipher.getInstance("DES/ECB/PKCS5Padding");

Cipher c1=Cipher.getInstance("DES");

当 以流加密方式请求以块划分的cipher时,可以在模式名后面跟上一次运算需要操作的bit数目,例如采用"DES/CFB8/NoPadding"和 "DES/OFB32/PKCS5Padding"形式的transformation参数。如果没有指定数目,则使用提供者指定的默认值(例如 SunJCE提供者使用的默认值是64bit)。

getInstance工厂方法返回的对象没有进行初始化,因此在使用前必须进行初始化。

通过getInstance得到的Cipher对象必须使用下列四个模式之一进行初始化,这四个模式在Cipher类中被定义为final integer常数,我们可以使用符号名来引用这些模式:

ENCRYPT_MODE,加密数据

DECRYPT_MODE,解密数据

WRAP_MODE,将一个Key封装成字节,可以用来进行安全传输

UNWRAP_MODE,将前述已封装的密钥解开成java.security.Key对象

每个Cipher初始化方法使用一个模式参数opmod,并用此模式初始化Cipher对象。此外还有其他参数,包括密钥key、包含密钥的证书certificate、算法参数params和随机源random。

我们可以调用以下的init方法之一来初始化Cipher对象:

public void init(int opmod,Key key);

public void init(int opmod,Certificate certificate);

public void init(int opmod,Key key,SecureRandom random);

public void init(int opmod,Certificate certificate,SecureRandom random);

public void init(int opmod,Key key,AlgorithmParameterSpec params);

public void init(int opmod,Key key,AlgorithmParameterSpec params,SecureRandom random);

public void init(int opmod,Key key,AlgorithmParameters params);

public void init(int opmod,Key key,AlgorithmParameters params,SecureRandom random);

必须指出的是,加密和解密必须使用相同的参数。当Cipher对象被初始化时,它将失去以前得到的所有状态。即,初始化Cipher对象与新建一个Cipher实例然后将它初始化是等价的。

二,可以调用以下的doFinal()方法之一完成单步的加密或解密数据:

public byte[] doFinal(byte[] input);

public byte[] doFinal(byte[] input,int inputOffset,int inputLen);

public int doFinal(byte[] input,int inputOffset,int inputLen,byte[] output);

public int doFinal(byte[] input,int inputOffset,int inputLen,byte[] output,int outputOffset);

在多步加密或解密数据时,首先需要一次或多次调用update方法,用以提供加密或解密的所有数据:

public byte[] update(byte[] input);

public byte[] update(byte[] input,int inputOffset,int inputLen);

public int update(byte[] input,int inputOffset,int inputLen,byte[] output);

public int update(byte[] input,int inputOffset,int inputLen,byte[] output,int outputOffset);

如果还有输入数据,多步操作可以使用前面提到的doFinal方法之一结束。如果没有数据,多步操作可以使用下面的doFinal方法之一结束:

public byte[] doFinal();

public int doFinal(byte[] output,int outputOffset);

如果在transformation参数部分指定了padding或unpadding方式,则所有的doFinal方法都要注意所用的padding或unpadding方式。

调用doFinal方法将会重置Cipher对象到使用init进行初始化时的状态,就是说,Cipher对象被重置,使得可以进行更多数据的加密或解密,至于这两种模式,可以在调用init时进行指定。

三,包裹wrap密钥必须先使用WRAP_MODE初始化Cipher对象,然后调用以下方法:

public final byte[] wrap(Key key);

如果将调用wrap方法的结果(wrap后的密钥字节)提供给解包裹unwrap的人使用,必须给接收者发送以下额外信息:

(1)密钥算法名称:

密钥算法名称可以调用Key接口提供的getAlgorithm方法得到:

public String getAlgorithm();

(2)被包裹密钥的类型(Cipher.SECRET_KEY,Cipher.PRIVATE_KEY,Cipher.PUBLIC_KEY)

sourcelink: ;nid=41716order=tid=

为了对调用wrap方法返回的字节进行解包,必须先使用UNWRAP_MODE模式初始化Cipher对象,然后调用以下方法 :

public final Key unwrap(byte[] wrappedKey,String wrappedKeyAlgorithm,int wrappedKeyType));

其 中,参数wrappedKey是调用wrap方法返回的字节,参数wrappedKeyAlgorithm是用来包裹密钥的算法,参数 wrappedKeyType是被包裹密钥的类型,该类型必须是Cipher.SECRET_KEY,Cipher.PRIVATE_KEY, Cipher.PUBLIC_KEY三者之一。

四,SunJCE提供者实现的cipher算法使用如下参数:

(1)采用CBC、CFB、OFB、PCBC模式的DES、DES-EDE和Blowfish算法。,它们使用初始化向量IV作为参数。可以使用javax.crypto.spec.IvParameterSpec类并使用给定的IV参数来初始化Cipher对象。

(2)PBEWithMD5AndDES使用的参数是一个由盐值和迭代次数组成的参数集合。可以使用javax.crypto.spec.PBEParameterSpec类并利用给定盐值和迭代次数来初始化Cipher对象。

注意:如果使用SealedObject类,就不必为解密运算参数的传递和保存担心。这个类在加密对象内容中附带了密封和加密的参数,可以使用相同的参数对其进行解封和解密。

Cipher 中的某些update和doFinal方法允许调用者指定加密或解密数据的输出缓存。此时,保证指定的缓存足够大以容纳加密或解密运算的结果是非常重要 的

用Java编写打印一段图形(类似菱形)的程序

这个题目主要又两个难点:1.$符号不是一直增加,而是先增加,后减少。2需要在$前补空格。

代码如下:

public class PrintDollar {

public static void main(String[] args) {

// 总行数,可以修改

int row = 5;

// 每一行的$符号数量

int dollarNumber;

// 追加的空格数量

int spaceNumber;

String dollar = "$";

for (int i = 1; i = row; i++) {

// 每一行输出的字符

String printString = "";

/*

* 判断行数是否超过了一半,超过一半$符号开始减少

*/

if (i * 2 - 1 row) {

// 行数超过一半的情况

dollarNumber = (row - i) * 2 + 1;

spaceNumber = (row - dollarNumber) / 2;

} else {

// 行数没超过一半的情况

dollarNumber = i * 2 - 1;

spaceNumber = (row - dollarNumber) / 2;

}

//追加空格

for (int j = 0; j spaceNumber; j++) {

printString += " ";

}

//追加$符号

for (int j = 0; j dollarNumber; j++) {

printString += dollar;

}

System.out.println(printString);

}

}

}


文章标题:关于多段图java代码的信息
文章源于:http://www.wjwzjz.com/article/hgjjpd.html
在线咨询
服务热线
服务热线:028-86922220
TOP