📄 aucserv.html
字号:
length);
if(inputLine !=null)
System.out.println("input="+inputLine);
if(length<0) {
moreData=false;
}
}
if(moreData) {
length = instream.readLine(
tmpbuffer,
0,
tmpbuffer.length);
inputLine = new String (tmpbuffer, 0, 0,
length);
if(inputLine.indexOf("desc") >=0) {
length = instream.readLine(
tmpbuffer,
0,
tmpbuffer.length);
inputLine = new String (tmpbuffer, 0, 0,
length);
length = instream.readLine(
tmpbuffer,
0,
tmpbuffer.length);
inputLine = new String (tmpbuffer, 0, 0,
length);
System.out.println("desc="+inputLine);
}
}
while(inputLine.indexOf(boundary)
>0 && moreData) {
length = instream.readLine(
tmpbuffer,
0,
tmpbuffer.length);
inputLine = new String (tmpbuffer, 0, 0,
length);
}
if(moreData) {
length = instream.readLine(
tmpbuffer,
0,
tmpbuffer.length);
inputLine = new String (tmpbuffer, 0, 0,
length);
if(inputLine.indexOf("filename") >=0) {
int startindex=inputLine.indexOf(
"filename");
System.out.println("file name="+
inputLine.substring(
startindex+10,
inputLine.indexOf("\"",
startindex+10)));
length = instream.readLine(
tmpbuffer,
0,
tmpbuffer.length);
inputLine = new String (tmpbuffer, 0, 0,
length);
}
}
byte fileBytes[]=new byte[50000];
int offset=0;
if (moreData) {
while(inputLine.indexOf(boundary)
>0 && moreData) {
length = instream.readLine(
tmpbuffer,
0,
tmpbuffer.length);
inputLine = new String (tmpbuffer, 0, 0, length);
if(length>0 && (
inputLine.indexOf(boundary) <0)) {
System.arraycopy(
tmpbuffer,
0,
fileBytes,
offset,
length);
offset+=length;
} else {
moreData=false;
}
}
}
// trim last two newline/return characters
// before using data
for(int i=0;i<offset-2;i++) {
System.out.print((char)fileBytes[i]);
}
}
out.println("</body></html>");
out.close();
}
}
</PRE>
<A NAME="thrd"></A>
<H3>Threading</H3>
A servlet must be able to handle multiple concurrent requests.
Any number of end users at any given time could invoke the
servlet, and while the <CODE>init</CODE> method is always
run single-threaded, the <CODE>service</CODE> method is
multi-threaded to handle multiple requests.
<P>
This means any static or public fields accessed by the
<CODE>service</CODE> method should be restricted
to simple thread access. The example below uses the
<CODE>synchronized</code> keyword to restrict access to a counter
so it can only be updated by one thread at a time:
<PRE>
int counter
Boolean lock = new Boolean(true);
synchronized(lock){
counter++;
}
</PRE>
<A NAME="https"></A>
<H3>HTTPS</H3>
Many servers, browsers, and the Java Plug-In have the ability to support
the secure HTTP protocol called HTTPS. HTTPS is similar to HTTP except the
data is transmitted over a secure socket layer (SSL) instead of
a normal socket connection. Web servers often listen for HTTP
requests on one port while listening for HTTPS requests on another.
<P>
The encrypted data that is sent over the network includes checks to verify
if the data has been tampered in transit. SSL also authenticates
the webserver to its clients by providing a public key certificate. In
SSL 3.0 the client can also authenticate itself with the server, again using
a public key certificate.
<P>
Public key cryptography (also called asymmetric key encryption) uses a public
and private key pair.
Any message encrypted (made unintelligible) with the private key in the pair
can only be decrypted with the corresponding public key.
Certificates are digitally signed statements generated from a trusted
third party Certificate Authority. The Certificate Authority needs proof
that you are who you say you are because clients will be trusting the certificate
they receive. It is this certificate that contains the public key in the public
and private key pair. The certificate is signed by the private key
of the Certificate Authority, and most browsers know the public key for the
main Certificate Authorities.
<P>
While public key encryption is good for authentication purposes, it is
not as fast as symmetric key encryption and so the SSL protocol uses both types
of keys in the lifecycle of an SSL connection. The client and server begin
an HTTPS transaction with a connection initialization or handshaking phase.
<P>
It is in the handshaking stage that the server is authenticated using the
certificate that the client has received. The client uses the server's public
key to encrypt messages sent to the server. After the client has been
authenticated and the encryption algorithm or cipher has been agreed between
the two parties, new symmetric session keys are used to encrypt and
decrypt any further communication.
<P>
The encryption algorithm or cipher can be one of many popular algorithms
like Rivest Shamir and Adleman (RSA) or Data Encryption Standard (DES). The
greater the number of bits used to make the key, the more difficult
it is to break into using brute force search techniques.
<P>
HTTPS using public key cryptography and certificates lets you provide
the amount of privacy your application needs for safe and secure
transactions. Servers, browsers, and Java Plug-In have their own
setup for enabling HTTPS using SSL communications. In general, the steps
involve the following:
<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Get a private key and a digitally-signed certificate with the
matching public key.</FONT>
<P>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Install the certificate in a location specified by the software
you are using (server, browser, or Java Plug-In).</FONT>
<P>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">Enable SSL features and specify your certificate and private key
files as instructed in your documentation.</FONT>
</UL>
You should enable SSL features according to your specific application
requirements
depending on the level of security you need. For example, you do not need
to verify the identity of customers browsing auction items, but you will
want to encrypt credit card and other personal information supplied when
buyers and sellers register to participate.
<P>
HTTPS can be used for any data not just HTTP web pages. Programs written in
the Java language can be downloaded over an HTTPS connection, and you can open
a connection to a HTTPS server in the Java Plug-in. To write a program in the
Java language that uses SSL. SSL requires an SSL library and a detailed knowledge
of the HTTPS handshaking process. Your SSL library should cover the necessary
steps as this information is restricted by export security control.
<P ALIGN="RIGHT">
<FONT SIZE="-1">[<A HREF="#top">TOP</A>]</FONT>
</FONT>
</TD>
</TR>
</TABLE>
<!-- ================ -->
<!-- End Main Content -->
<!-- ================ -->
</TD>
</TR>
</TABLE>
<!-- Copyright Insert -->
<BR CLEAR="ALL">
<FORM ACTION="/cgi-bin/search.cgi" METHOD="POST">
<TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="5">
<TR>
<TD VALIGN="TOP">
<P ALIGN=CENTER>
<FONT SIZE="-1" COLOR="#999999" FACE="Verdana, Arial, Helvetica, sans-serif">
[ This page was updated: <!-- new date --> 13-Oct-99 ]</font></P>
</TD>
</TR>
<TR>
<TD BGCOLOR="#CCCCCC">
<IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
</TR>
<TR>
<TD>
<CENTER>
<FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="http://java.sun.com/products/">Products & APIs</A> |
<A HREF="/developer/index.html">Developer Connection</A> |
<A HREF="/developer/infodocs/index.shtml">Docs & Training</A> |
<A HREF="/developer/support/index.html">Online Support</A><BR>
<A HREF="/developer/community/index.html">Community Discussion</A> |
<A HREF="http://java.sun.com/industry/">Industry News</A> |
<A HREF="http://java.sun.com/solutions">Solutions Marketplace</A> |
<A HREF="http://java.sun.com/casestudies">Case Studies</A>
</FONT>
</CENTER>
</TD>
</TR>
<TR>
<TD BGCOLOR="#CCCCCC">
<IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
</TR>
<TR>
<TD ALIGN="CENTER">
<FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="http://java.sun.com/docs/glossary.html">Glossary</A> -
<A HREF="http://java.sun.com/applets/">Applets</A> -
<A HREF="http://java.sun.com/docs/books/tutorial/">Tutorial</A> -
<A HREF="http://java.sun.com/jobs/">Employment</A> -
<A HREF="http://java.sun.com/nav/business/">Business & Licensing</A> -
<A HREF="http://java.sun.com/javastore/">Java Store</A> -
<A HREF="http://java.sun.com/casestudies/">Java in the Real World</A>
</FONT>
</TD>
</TR>
<TR>
<TD>
<CENTER>
<FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
<a href="/siteinfo/faq.html">FAQ</a> |
<a href="/feedback/index.html">Feedback</a> |
<a href="http://www.dynamicdiagrams.net/mapa/cgi-bin/help.tcl?db=javasoft&dest=http://java.sun.com/">Map</a> |
<A HREF="http://java.sun.com/a-z/index.html">A-Z Index</A>
</FONT>
</CENTER>
</TD>
</TR>
<TR>
<TD>
<TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="0">
<TR>
<TD WIDTH="50%">
<FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
For more information on Java technology<BR>
and other software from Sun Microsystems, call:<BR>
</FONT>
<FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, sans-serif">
(800) 786-7638<BR></FONT>
<FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
Outside the U.S. and Canada, dial your country's
<A HREF="http://www.att.com/business_traveler/attdirecttollfree/">AT&T Direct Access Number</A> first.<BR>
</FONT>
</TD>
<TD ALIGN="RIGHT" WIDTH="50%">
<A HREF="http://www.sun.com"><IMG SRC="/images/lgsun.gif" width="64" height="30" border="0" ALT="Sun Microsystems, Inc."></A><BR>
<FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
Copyright © 1995-99
<A HREF="http://www.sun.com">Sun Microsystems, Inc.</A><BR>
All Rights Reserved.
<a href="http://www.sun.com/share/text/SMICopyright.html">Legal Terms</a>.
<A HREF="http://www.sun.com/privacy/">Privacy Policy</A>.
</FONT>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</FORM>
<!-- End Copyright Insert -->
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -