下载本文示例代码
天极IT资讯短信服务 电脑小技巧
function check4() { if (dn.mobile.value.length!=11) { alert("手机号码不正确!"); dn.mobile.focus(); return false; } return true; }
资费:包月5元手机:
介绍:细处着手,巧处用功。高手和菜鸟之间的差别就是:高手什么都知道,菜鸟知道一些。电脑小技巧收集最新奇招高招,让你轻松踏上高手之路。
Java关键字导航
网络 J2ME 手机游戏 JavaCard Struts 游戏 分析器 JAAS EJB JavaMail 设计模式 J2EE Java Servlet 在网络上的编程应用,如利用Servlet 上传和下载文件、Servlet 的数据库编程、在Servlet 中发送和接受邮件以及Java Servlet 在RMI和XML等方面的应用,由于篇幅有限,在这里就不在多介绍了,下面再举一个Servlet 上传的例子。 在Web 应用程序中,用户向服务器上传文件是非常普遍的操作。使用Servlet 实现文件的上传是比较简单的。 编程思路:下面的UploadServlet.java ,其主要功能为从InputStream 中读取文件内容,将上传文件保存在根目录下,且文件名与上传文件的文件名一致。 UploadServlet.java 的源代码如下:(代码节选)
import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class UploadServlet extends HttpServlet{//default maximum allowable file size is 1000kstatic final int MAX_SIZE = 1024000;//instance variables to store root and success messageString rootPath, successMessage;/*** init method is called when servlet is initialized.*/public void init(ServletConfig config) throws ServletException{super.init(config);//get path in which to save filerootPath = config.getInitParameter("RootPath");if (rootPath == null){rootPath = "/";}/*Get message to show when upload is complete. Used only ifa success redirect page is not supplied.*/successMessage = config.getInitParameter("SuccessMessage");if (successMessage == null){successMessage = "File upload complete!";}}/*** doPost reads the uploaded data from the request and writes* it to a file.*/public void doPost(HttpServletRequest request,HttpServletResponse response){ServletOutputStream out=null;DataInputStream in=null;FileOutputStream fileOut=null;try{/*set content type of response and get handle to outputstream in case we are unable to redirect client*/response.setContentType("text/plain");out = response.getOutputStream();//get content type of client requestString contentType = request.getContentType();out.println("\ncontentType= " contentType);//make sure content type is multipart/form-dataif(contentType != null && contentType.indexOf("multipart/form-data") != -1){//open input stream from client to capture upload filein = new DataInputStream(request.getInputStream());//get length of content dataint formDataLength = request.getContentLength();out.println("\nContentLength= " formDataLength);//allocate a byte array to store content databyte dataBytes[] = new byte[formDataLength];//read file into byte arrayint bytesRead = 0;int totalBytesRead = 0;int sizeCheck = 0;while (totalBytesRead < formDataLength){//check for maximum file size violationsizeCheck = totalBytesRead in.available();if (sizeCheck > MAX_SIZE){out.println("Sorry, file is too large to upload.");return;}......................共2页。 1 2 :
天极IT资讯短信服务 电脑小技巧
function check4() { if (dn.mobile.value.length!=11) { alert("手机号码不正确!"); dn.mobile.focus(); return false; } return true; }
资费:包月5元手机:
介绍:细处着手,巧处用功。高手和菜鸟之间的差别就是:高手什么都知道,菜鸟知道一些。电脑小技巧收集最新奇招高招,让你轻松踏上高手之路。
Java关键字导航
网络 J2ME 手机游戏 JavaCard Struts 游戏 分析器 JAAS EJB JavaMail 设计模式 J2EE Java Servlet 在网络上的编程应用,如利用Servlet 上传和下载文件、Servlet 的数据库编程、在Servlet 中发送和接受邮件以及Java Servlet 在RMI和XML等方面的应用,由于篇幅有限,在这里就不在多介绍了,下面再举一个Servlet 上传的例子。 在Web 应用程序中,用户向服务器上传文件是非常普遍的操作。使用Servlet 实现文件的上传是比较简单的。 编程思路:下面的UploadServlet.java ,其主要功能为从InputStream 中读取文件内容,将上传文件保存在根目录下,且文件名与上传文件的文件名一致。 UploadServlet.java 的源代码如下:(代码节选)
import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class UploadServlet extends HttpServlet{//default maximum allowable file size is 1000kstatic final int MAX_SIZE = 1024000;//instance variables to store root and success messageString rootPath, successMessage;/*** init method is called when servlet is initialized.*/public void init(ServletConfig config) throws ServletException{super.init(config);//get path in which to save filerootPath = config.getInitParameter("RootPath");if (rootPath == null){rootPath = "/";}/*Get message to show when upload is complete. Used only ifa success redirect page is not supplied.*/successMessage = config.getInitParameter("SuccessMessage");if (successMessage == null){successMessage = "File upload complete!";}}/*** doPost reads the uploaded data from the request and writes* it to a file.*/public void doPost(HttpServletRequest request,HttpServletResponse response){ServletOutputStream out=null;DataInputStream in=null;FileOutputStream fileOut=null;try{/*set content type of response and get handle to outputstream in case we are unable to redirect client*/response.setContentType("text/plain");out = response.getOutputStream();//get content type of client requestString contentType = request.getContentType();out.println("\ncontentType= " contentType);//make sure content type is multipart/form-dataif(contentType != null && contentType.indexOf("multipart/form-data") != -1){//open input stream from client to capture upload filein = new DataInputStream(request.getInputStream());//get length of content dataint formDataLength = request.getContentLength();out.println("\nContentLength= " formDataLength);//allocate a byte array to store content databyte dataBytes[] = new byte[formDataLength];//read file into byte arrayint bytesRead = 0;int totalBytesRead = 0;int sizeCheck = 0;while (totalBytesRead < formDataLength){//check for maximum file size violationsizeCheck = totalBytesRead in.available();if (sizeCheck > MAX_SIZE){out.println("Sorry, file is too large to upload.");return;}......................共2页。 1 2 :
下载本文示例代码
Java Servlet 编程及应用之八Java Servlet 编程及应用之八Java Servlet 编程及应用之八Java Servlet 编程及应用之八Java Servlet 编程及应用之八Java Servlet 编程及应用之八Java Servlet 编程及应用之八Java Servlet 编程及应用之八Java Servlet 编程及应用之八Java Servlet 编程及应用之八Java Servlet 编程及应用之八Java Servlet 编程及应用之八Java Servlet 编程及应用之八Java Servlet 编程及应用之八Java Servlet 编程及应用之八
阅读(123) | 评论(0) | 转发(0) |