ÓÃJSPÀ´ÊµÏÖÎļþÏÂÔØ¹¦Äܵļ¸ÖÖ·½Ê½
1.×îÖ±½Ó×î¼òµ¥µÄ£¬·½Ê½ÊǰÑÎļþµØÖ·Ö±½Ó·Åµ½htmlÒ³ÃæµÄÒ»¸öÁ´½ÓÖС£ÕâÑù×öµÄȱµãÊǰÑÎļþÔÚ·þÎñÆ÷ÉϵÄ·¾¶±©Â¶ÁË£¬²¢ÇÒ»¹ÎÞ·¨¶ÔÎļþÏÂÔØ½øÐÐÆäËüµÄ¿ØÖÆ£¨ÈçȨÏÞ£©¡£Õâ¸ö¾Í²»Ð´Ê¾ÀýÁË¡£
2.ÔÚ·þÎñÆ÷¶Ë°ÑÎļþת»»³ÉÊä³öÁ÷£¬Ð´Èëµ½response£¬ÒÔresponse°ÑÎļþ´øµ½ä¯ÀÀÆ÷£¬ÓÉä¯ÀÀÆ÷À´ÌáʾÓû§ÊÇ·ñÔ¸Òâ±£´æÎļþµ½±¾µØ¡£
3.¼ÈÈ»ÊÇJSPµÄ»°£¬»¹ÓÐÒ»ÖÖ·½Ê½¾ÍÊÇÓÃAppletÀ´ÊµÏÖÎļþµÄÏÂÔØ¡£²»¹ý¿Í»§Ê×ÏȵÃÐÅÈÎÄãµÄÕâ¸öAppletС³ÌÐò£¬ÓÉÕâ¸ö³ÌÐòÀ´½ÓÊÜÓÉservlet·¢ËÍÀ´µÄÊý¾ÝÁ÷£¬²¢Ð´Èëµ½±¾µØ¡£
Servlet¶ËʾÀý
public void service(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException {
res.setContentType(\" text/plain \");
OutputStream outputStream = null;
try {
outputStream = res.getOutputStream();//°ÑÎļþ·¾¶ÎªsrcFileµÄÎļþдÈëoutputStreamÖÐ
popFile(srcFile, outputStream)) ;
} catch (IOException e) {
e.printStackTrace();
}
}
JApplet¶ËʾÀý
URLConnection con;
try {
//urlÊDZ»µ÷ÓõÄSERVLETµÄÍøÖ· Èç *.do
con=url.openConnection();
con.setUseCaches(false);
con.setDoInput(true);
con.setDoOutput(true);
con.setRequestProperty(\"Content-Type\",\"application/octet-stream\");
InputStream in = con.getInputStream();
ProgressMonitorInputStream pmInputStream = new ProgressMonitorInputStream(pane, \"ÕýÔÚ´Ó·þÎñÆ÷ÏÂÔØÎļþÄÚÈÝ\", in);
ProgressMonitor pMonitor = pmInputStream.getProgressMonitor();
pMonitor.setMillisToDecideToPopup(3);
pMonitor.setMillisToPopup(3);//localfilepath±¾µØÂ·¾¶,localstrÎļþÎļþ¼Ð£¬filename±¾µØÎļþÃû
String localfilepath = localstr filename ;//·½·¨saveFilsaveFileeÊǰÑÊäÈëÁ÷pmInputStreamдµ½ÎļþlocalfilepathÖÐ
if(saveFilsaveFilee(localfilepath,pmInputStream)){¡¡¡¡¡¡¡¡ openLocalFile(localfilepath);
} URLConnection con;
try {
con = url.openConnection();//urlÊDZ»µ÷ÓõÄSERVLETµÄÍøÖ· Èç *.do ¡¡¡¡
con.setUseCaches(false);
con.setDoInput(true);
con.setDoOutput(true);
con.setRequestProperty(\"Content-Type\",\"application/octet-stream\");
OutputSt
Ïà¹ØÎĵµ£º
¶ÔÓÚHTMÍøÒ³£¬¼ÓÈ룺
<meta HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<meta HTTP-EQUIV="expires" CONTENT="0">
È»ºó£¬jspÒ³ÃæÖмÓÈ룺
<%
response.setHeader("Cache-Control","no-store") ......
<%@ page language="java" import="kg.TestBean2;" %>
<%@ page contentType="text/html;charset=gb2312" %>
<html>
<head>
<title>HelloBean</title>
</head>
<body>
<%--
<%
kg.TestBean2 testbean=(kg.TestBean2)session.setAttribute("testbean");
if ......
<%@ page language="java" import="kg.TestBean2;" %>
<%@ page contentType="text/html;charset=gb2312" %>
<html>
<head>
<title>HelloBean</title>
</head>
<body>
<%--
<%
kg.TestBean2 testbean=(kg.TestBean2)session.setAttribute("testbean");
if ......
ÒÔǰÓÐÌáµ½¹ýÂÒÂëÎÊÌ⣬×î½üÔÚʹÓÃwindow.openʱÓÖ³öÏÖ´ËÀàÎÊÌ⣬ÏÖ½â¾öÈçÏ£º
1£ºÊ¹ÓÃencodeURIComponentº¯Êý¶Ô²ÎÊý½øÐд¦Àí£¬ÀýÈ磺window.open("html.jsp?name=" + encodeUrlComponent(value)));
2£ºÐÞ¸Ätomcat·þÎñÆ÷µÄserver.xmlÎļþÌí¼Ó£ºuseBodyEncodingForURI="true"»òÕß
URIEncoding=" ......
ʹÓÃRandomAccessFileÀàÌṩµÄ¹¦ÄÜÀ´ÊµÏÖÎļþÉÏ´«¡£µ±ÎÒÃÇÏë¶ÔÒ»¸öÎļþ½øÐжÁд²Ù×÷ʱ£¬¿ÉÒÔ´´½¨Ò»¸öÖ¸Ïò¸ÃÎļþµÄRandomAccessFileÁ÷¼´¿É£¬ÕâÑù¼È¿ÉÒÔ´ÓÕâ¸öÁ÷ÖжÁÈ¡Õâ¸öÎļþµÄÊý¾Ý£¬Ò²Í¨¹ýÕâ¸öÁ÷дÈëÊý¾Ý¸øÕâ¸öÎļþ¡£
ÀûÓÃJavaBean¸ºÔð½«Óû§Ñ¡ÔñµÄÎļþÉÏ´«µ½·þÎñÆ÷¡£bean¿ÉÒÔÈÃÄÚÖöÔÏórequestµ÷Ó÷½·¨getInputStream£ ......