ÓÃJSPÏÂÔØwordÎļþ
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="java.net.*"%>
<%
String filename = "";
if (request.getParameter("file") != null) {
filename = request.getParameter("file");
}
response.setContentType("application/msword");
response.setHeader("Content-disposition","attachment; filename="+filename);
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("" + filename)));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff,0,bytesRead);
}
} catch(final IOException e) {
System.out.println ( "³öÏÖIOException." + e );
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
return;
%>
Ïêϸ³ö´¦²Î¿¼£ºhttp://www.jb51.net/article/2631.htm
Ïà¹ØÎĵµ£º
À´Ô´ÓÚ¡¶Java¡¢javaEEÈí¼þ¹¤³Ìʦ¾ÍÒµÇóÖ°Êֲᡷ
1 HttpServletRequestÀàµÄrequest¶ÔÏ󣺴ú±íÇëÇó¶ÔÏó£¬Ö÷ÒªÓÃÓÚ½ÓÊÜ¿Í»§¶Ëͨ¹ýHTTPÐÒéÁ¬½Ó´«Êäµ½·þÎñÆ÷µÄÊý¾Ý¡£
2 HttpServletResponseÀàµÄresponse£º´ú±íÏìÓ¦¶ÔÏó£¬Ö÷ÒªÓÃÓÚÏò¿Í»§¶Ë·¢ËÍÊý¾Ý¡£
3 JspWriterÀàµÄout¶ÔÏó:Ö÷ÒªÓÃÓÚÏò¿Í»§¶ËÊä³öÊý¾Ý£¬OutµÄ»ùÀàÊÇJspWriter¡ ......
Ò»°ã£¬ÔںܶàÓ¦ÓÃϵͳÖУ¬Óû§¶à´ÎÌá½»Öظ´Êý¾ÝÊÇÒ»¸öºÜÑÏÖصÄÎÊÌ⣬»áµ¼ÖÂÓ¦ÓÃϵͳÖкܶàÀ¬»øÊý¾Ý£¬ÔÚStrutsÖпò¼ÜÖУ¬ÓÐTOKEN»úÖÆÀ´·ÀÖ¹Óû§Ìá½»Öظ´Êý¾Ý£¬ÕâÊÇÒ»¸öºÜºÃµÄ°ì·¨£¬µ«ÊÇ£¬TOKEN»úÖƱØÐëµÃÓõ½html:form±êÇ©£¬ÎÒ²»Ï²»¶ÓÃÕâ¸ö±êÇ©£¬ÎÒ¾õµÃÊÇÒ»¸öÀÛ׸£¬ËùÒÔÎÒÈ¥µôHTML:FORM±êÇ©£¬ÖØж¨ÒåTOK ......
JSP/Servletת·¢ÓëÖض¨ÏòµÄÇø±ð
¾¡¹ÜHttpServletResponse.sendRedirect ·½·¨ºÍRequestDispatcher.forward ·½·¨¶¼¿ÉÒÔÈÃä¯ÀÀÆ÷»ñµÃÁíÍâÒ»¸öURLËùÖ¸ÏòµÄ×ÊÔ´£¬µ«Á½ÕßµÄÄÚ²¿ÔËÐлúÖÆÓÐןܴóµÄÇø±ð¡£
¡¡¡¡ÏÂÃæÊÇHttpServletResponse.sendRedirect ·½·¨ÊµÏÖµÄÇëÇóÖض¨ÏòÓëRequestDispatcher.forward ·½·¨ÊµÏÖµÄÇëÇó ......
JSPµÄÖ¸ÁîÊÇÓÃÀ´°üº¬ÍⲿÎļþ»òÊǽøÐÐÒ³ÃæÈ«¾ÖÉèÖõģ»ËüµÄÓÐÈýÖÖ£¬·Ö±ðÊÇpage£¬include£¬taglibÖ¸Áî
1.pageÖ¸Áî
ÐÎÈç<%@page ÊôÐÔ='Öµ' ÊôÐÔ='Öµ' ........ %>
ÊôÐÔÓУº
language=''java'' £º É趨jspÒ³ÃæµÄ½Å±¾ÓïÑÔ£¬Ä¿Ç°Ö»Ö§³Öjava£¬Ä¬ÈÏÊÇjava
......
<%@ page autoFlush="false" contentType="text/html;charset=utf-8" language="java" import="java.io.*,java.awt.Image,java.awt.image.*,com.sun.image.codec.jpeg.*,java.sql.*,com.jspsmart.upload.*,java.util.*,java.io.FileInputStream,java.io.FileOutputStream,java.awt.*"%>
<%@ page import="com.b ......