JSPʵÏÖÎļþÉÏ´«
ʹÓÃRandomAccessFileÀàÌṩµÄ¹¦ÄÜÀ´ÊµÏÖÎļþÉÏ´«¡£µ±ÎÒÃÇÏë¶ÔÒ»¸öÎļþ½øÐжÁд²Ù×÷ʱ£¬¿ÉÒÔ´´½¨Ò»¸öÖ¸Ïò¸ÃÎļþµÄRandomAccessFileÁ÷¼´¿É£¬ÕâÑù¼È¿ÉÒÔ´ÓÕâ¸öÁ÷ÖжÁÈ¡Õâ¸öÎļþµÄÊý¾Ý£¬Ò²Í¨¹ýÕâ¸öÁ÷дÈëÊý¾Ý¸øÕâ¸öÎļþ¡£
ÀûÓÃJavaBean¸ºÔð½«Óû§Ñ¡ÔñµÄÎļþÉÏ´«µ½·þÎñÆ÷¡£bean¿ÉÒÔÈÃÄÚÖöÔÏórequestµ÷Ó÷½·¨getInputStream£¨£©»ñµÃÒ»¸öÊäÈëÁ÷£¬Í¨¹ýÕâ¸öÊäÈëÁ÷¶ÁÈë¿Í»§ÉÏ´«µÄÈ«²¿ÐÅÏ¢£¬°üÀ¨ÎļþµÄÄÚÈÝÒÔ¼°±íµ¥ÓòµÄÐÅÏ¢¡£bean¿ÉÒÔ´ÓÉÏ´«µÄÈ«²¿ÐÅÏ¢ÖзÖÀë³öÎļþµÄÄÚÈÝ£¬²¢±£´æÔÚ·þÎñÆ÷¶Ë¡£°´ÕÕHTTPÐÒ飬Îļþ±íµ¥Ìá½»µÄÐÅÏ¢ÖУ¬Ç°4Ðкͺó5ÐÐÊÐ±íµ¥±¾ÉíµÄÐÅÏ¢£¬Öм䲿·Ö²ÅÊÇ¿Í»§Ìá½»µÄÎļþµÄÄÚÈÝ¡£beanͨ¹ýʹÓÃRandomAccessFileÁ÷»ñÈ¡ÎļþµÄÄÚÈÝ£¬¼´È¥µô±íµ¥µÄÐÅÏ¢¡£Ê×ÏÈ£¬bean½«¿Í»§Ìá½»µÄÈ«²¿ÐÅÏ¢±£´æΪһ¸öÁÙʱÎļþ£¬¸ÃÎļþµÄÃû×ÖÊÇ¿Í»§µÄsession¶ÔÏóµÄid£¨²»Í¬¿Í»§µÄÕâ¸öidÊDz»Í¬µÄ£©£¬È»ºó¶ÁÈ¡¸ÃÁÙʱÎļþµÄµÚ2ÐУ¬ÕâÒ»ÐÐÖк¬Óпͻ§ÉÏ´«µÄÎļþµÄÎÄ×Ö£¬»ñÈ¡Õâ¸öÃû×Ö£¬ÔÙ»ñÈ¡µÚ4ÐнáÊøµÄλÖã¬ÒÔ¼°µ¹ÊýµÚ6ÐеĽáÊøλÖã¬ÒòΪÕâÁ½¸öλÖÃÖ®¼äµÄÄÚÈÝÊÇÉÏ´«ÎļþµÄÄÚÈÝ£¬È»ºó½«Õⲿ·ÖÄÚÈÝ´æÈëÎļþ£¬¸ÃÎļþµÄÃû×ֺͿͻ§ÉÏ´«µÄÎļþµÄÃû×Ö±£³ÖÒ»Ö¡£×îºóɾ³ýÁÙʱÎļþ¡£
JSPÒ³ÃæÖУº
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="boy" size="45"><br>
<input type="submit" name="g" value="Ìá½»">
</form>
ÕâÑùÑ¡ÔñÎļþÌá½»ºórequest¾Í»áÓÐÎļþÁ÷ÐÅÏ¢¡£
UpFile.java
package bean;
import java.io.*;
import javax.servlet.http.*;
public class UpFile
{
HttpServletRequest request;
HttpSession session;
String upFileMessage="";
public void setRequest(HttpServletRequest request)
{
this.request = request;
}
public void setSession(HttpSession session)
{
this.session = session;
}
public String getUpFileMessage()
{
String fileName = null;
try
{
String tempFileName = (String)session.getId(); //¿Í»§µÄsessionµÄid
File f1 = new File("F:\\workspace\\testUpLoadFile\\UpFiles", tempFileName);
FileOutputStream o = new FileOutputStream(f1);
InputStream in = request.getInputStream(); //»ñÈ¡ÇëÇóµÄ×Ö½ÚÁ÷
byte b[] =
Ïà¹ØÎĵµ£º
Ò»¡¢jspÁ¬½ÓOracle8/8i/9iÊý¾Ý¿â£¨ÓÃthinģʽ£©
¡¡¡¡testoracle.jspÈçÏ£º
¡¡¡¡<%@ page contentType="text/html;charset=gb2312"%>
¡¡¡¡<%@ page import="java.sql.*"%>
¡¡¡¡<html>
¡¡¡¡<body>
¡¡¡¡<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
¡¡¡¡Stri ......
JSP»ù±¾Óï·¨Ó붨Òå
ÏÈÀ´¿´Ò»¶Î¼òµ¥µÄС³ÌÐò£º
³ÌÐò£º
1.jsp
<html>
<head>
<title>example</title>
</head>
1
¡¡
<%@ page language=”java” %>
2
¡¡
<%@ page
contentType=”text/html,charset=”GB2312””>
3
¡¡ ......
Ò»¡¢°²×°JDK ¡¡¡¡Ê×ÏÈÏÂÔØJDK 5.0£¨JDK 5.0µÄÏÂÔØÒ³ÃæΪ£ºhttp://java.sun.com/j2se/1.5.0/download.jsp£©£» È»ºóÔËÐÐJDK 5.0°²×°³ÌÐòjdk-1_5_0_06-windows-i586-p.exe£¬°²×°¹ý³ÌÖÐËùÓÐÑ¡Ïî±£³ÖĬÈÏ£»×îºóÅäÖÃJDKµÄ»·¾³±äÁ¿£ºÔÚ“ÎҵĵçÄÔ”ÉϵãÓÒ¼ü—>“ÊôÐÔ”—>“¸ß¼¶”& ......
ÓÃÁËcommons-fileupload-1.2.jarºÍcommons-io-1.3.2.jarÕâÁ½¸ö°ü¡£
save.jsp
<%@ page language="java" contentType="text/html;charset=utf-8"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.regex.*"%>
<%@ page import="org.apache.co ......
javascriptдjavaû¹Øϵ,ÖÁÓÚΪʲôÃû×ÖÕâôÏà½ü,¿ÉÄÜÊÇÒòΪjavaºÜÓÐÃûÆøËùÒÔ°ÑÃû×ÖÈ¡³É²î²»¶àµÄ,Ò»ÖÖÐÂÓïÑÔ¸Õ³öÀ´µÄʱºòÒªµãÃûÆøÀ´³öÃû°É~~
javascriptËãÊÇÒ»ÖÖhtml½Å±¾ÄÜÖ±½ÓÖ´ÐеÄÓïÑÔ°É,jspÒª±àÒë²ÅÄÜÖ´ÐÐ,Äã×Ô¼ºÐ´¸öJSP²»¿ªtomcatÖ®ÀàµÄÊÇÎÞ·¨Ö´ÐеÄ.JSPºÍJAVAµÄÇø±ð,JSPËãÊÇJAVAÒ»ÖÖ¼¼Êõ°É,ÓÃÔÚÍøÒ³±à³ÌÉÏ,ÒòΪJAVA² ......