参考代码:
import javasecurityKey;
import javasecurityKeyException;
import javasecurityNoSuchAlgorithmException;
import javaxcryptoCipher;
import javaxcryptoIllegalBlockSizeException;
import javaxcryptoKeyGenerator;
import javaxcryptoNoSuchPaddingException;
import javaxcryptoSecretKey;
public class Test {
public static void main(String [] args) {
String Algorithm="DES"; //定义 加密算法,可用 DES,DESede,Blowfish
KeyGenerator keygen;
try {
keygen = KeyGeneratorgetInstance(Algorithm);
SecretKey deskey = keygengenerateKey();
Cipher ci = CiphergetInstance("DES");
//将其包装为byte[]发送
byte[] b = ciwrap(deskey);
//发送
//
//接收到后
//解封装
Key key = ciunwrap(b, Algorithm, CipherPRIVATE_KEY);
//
} catch (NoSuchAlgorithmException e) {
eprintStackTrace();
} catch (KeyException e) {
eprintStackTrace();
} catch (IllegalBlockSizeException e) {
eprintStackTrace();
} catch (NoSuchPaddingException e) {
eprintStackTrace();
}
}
}html页面和流本来就是各自独立的>开始页面:startjsp
<%@ page contentType="text/html; charset=GBK" %>
<% sessionremoveAttribute("task"); %>
<jsp:useBean id="task" scope="session" class="progressTaskBean"/>
<% tasksetRunning(true); %>
<% new Thread(task)start(); %>
<jsp:forward page="statusjsp"/>
状态页面:statusjsp
<%@ page contentType="text/html; charset=GBK" %>
<jsp:useBean id="task" scope="session" class="progressTaskBean"/>
<HTML>
<HEAD>
<TITLE>JSP进度条</TITLE>
<% if (taskisRunning()) { %>
<script type="" LANGUAGE="JavaScript">
setTimeout("location='statusjsp'", 1000);
</script>
<% } %>
</HEAD>
<bODY bgcolor="">
<H1 ALIGN="CENTER">JSP进度条</H1>
<H2 ALIGN="CENTER">
结果: <%= taskgetResult() %><BR>
<% int percent = taskgetPercent(); %>
<%= percent %>%
</H2>
<TABLE WIDTH="60%" ALIGN="CENTER"
CELLPADDING=0 CELLSPACING=2>
<TR>
<% for (int i = 10; i <= percent; i += 10) { %>
<TD WIDTH="10%" height="10" BGCOLOR="red"> </TD>
<% } %>
<% for (int i = 100; i > percent; i -= 10) { %>
<TD WIDTH="10%"> </TD>
<% } %>
</TR>
</TABLE>
<TABLE WIDTH="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD ALIGN="CENTER">
<% if (taskisRunning()) { %>
正在执行
<% } else { %>
<% if (taskisCompleted()) { %>
完成
<% } else if (!taskisStarted()) { %>
尚未开始
<% } else { %>
已停止
<% } %>
<% } %>
</TD>
</TR>
<TR>
<TD ALIGN="CENTER">
<BR>
<% if (taskisRunning()) { %>
<FORM METHOD="GET" ACTION="stopjsp">
<INPUT TYPE="SUBMIT" ="停止">
</FORM>
<% } else { %>
<FORM METHOD="GET" ACTION="startjsp">
<INPUT TYPE="SUBMIT" ="开始">
</FORM>
<% } %>
</TD>
</TR>
</TABLE>
</BODY></HTML>
停止页面:stopjsp
<%@ page contentType="text/html; charset=GBK" %>
<jsp:useBean id="task" scope="session" class="progressTaskBean"/>
<% tasksetRunning(false); %>
<jsp:forward page="statusjsp"/>
业务逻辑bean:TaskBeanjava
package progress;
import javaioSerializable;
public class TaskBean
implements Runnable, Serializable {
private int counter;
private int sum;
private boolean started;
private boolean running;
private int sleep;
public TaskBean() {
counter = 0;
sum = 0;
started = false;
running = false;
sleep = 100;
}
protected void work() {
try {
Threadsleep(sleep);
counter++;
sum += counter;
}
catch (InterruptedException e) {
setRunning(false);
}
}
public synchronized int getPercent() {
return counter;
}
public synchronized boolean isStarted() {
return started;
}
public synchronized boolean isCompleted() {
return counter == 100;
}
public synchronized boolean isRunning() {
return running;
}
public synchronized void setRunning(boolean running) {
thisrunning = running;
if (running) {
started = true;
}
}
public synchronized Object getResult() {
if (isCompleted()) {
return new Integer(sum);
}
else {
return null;
}
}
public void run() {
try {
setRunning(true);
while (isRunning() && !isCompleted()) {
work();
}
}
finally {
setRunning(false);
}
}
}Tomcat 介绍 如今,基于Web的应用越来越多,传统的Html已经满足不了如今的需求。我们需要一个交互式的Web,于是便诞生了各种Web语言。
如Asp,Jsp,Php等。当然,这些语言与传统的语言有着密切的联系,如Php基于C和C++语言,Jsp基于Java语言。Tomcat即是一个Jsp和Servlet
的运行平台。
Tomcat是一个免费的开源的Serlvet容器,它是Apache基金会的Jakarta项目中的一个核心项目,由Apache,Sun和其它一些公司及个人共同开发
而成。由于有了Sun的参与和支持,最新的Servlet和Jsp规范总能在Tomcat中得到体现。Tomcat被JavaWorld杂志的编辑选为2001年度最具创新
的java产品,可见其在业界的地位。
Tomcat最新版本是40x40x与3x的架构不同,而是重新设计的。Tomcat40x中采用了新的Servlet容器:Catalina,完整的实现了Servlet23
和Jsp12规范。Tomcat提供了各种平台的版本供下载,可以从>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)