zoukankan      html  css  js  c++  java
  • 服务器响应的生成:HTTP响应报头——HttpServletResponse接口的应用

    一,响应报头  

           响应报头允许服务器传递不能放在状态行中的附加响应信息,以及关于服务器的信息和对Request-URI所标识的资源进行下一步访问的信息    

            常用的响应报头    

                     Location     

                     Content-Type    

                     Referer      

     二,在Servlet中设置HTTP响应报头HttpServletResponse接口

                  使用HttpServletResponse的setHeader方法,参数为报头名字和报头的值。  和设置状态代码一样。必须在返回实际的文档之前指定相关的报头。    

                  setDateHeader(String headerName,Long 毫秒数):设置含有日期和整数的报头。 

                  setIntHeader(String header,int headerValue):将int类型的状态代码转换为String插入报头。

                  Http容许相同的报头多次出现,上面3中方法将替换任何同名的已有报头。而使 addHeader,addDateHeader和addIntHeader方法添加一个报头。  可以使用containsHeader发发进行检查是否已经设置了特定的报头。

                  HttpServletResponse常用的设置报头的方法。   

                           setContentType(String mimeType)方法设置Content-type报头。

                           setContentLength(int length)发发设置Content-length报头,用于浏览器持续性HTTP连接。   

                           addCookie(Cookie c)方法:向set-cookie报头插入一个cookie。   

                          sendRedirect(String url)方法,设置设置状态码和Location报头。

    三,构建Excel电子表格 (响应报头Content-type的应用)  

                 Excel至少接受3种不同格式的输出:用制表符分隔的数据,HTML表格和本地二进制格式。  使用Content-type响应报头告诉客户程序正在发送电子表格。使用setContentType设置Content-type响应头。Excel表格的MIME类型是application/vnd.ms-excel    

                使用制表符分隔的数据生成电子表格:  

                           response.setContentType(“application/vnd.ms-excel;charset=gb2312”); 

                           PrintWriter out = response.getWriter();   

                           输出含有制表符/t的一些数据,不需要输出HTML标签。

    四,servlet状态的维持和页面的自动重载。(servlet数据存储方式和Referer响应报头的应用)  

                servlet状态的维持,对于servlet或jsp需要较长时间来处理的请求:    

                          1,跨请求存储数据,维护状态     不专属任意客户的数据,存储在servlet的字段中。     对于用户专属数据,存储在HttpSession对象中。     对于其他servlet或jsp需要用到的数据,存储在ServletContext中。   

                           2,在请求发送给客户程序后,继续进行处理。     启动一个线程响应请求,响应之后自动结束线程。另个线程将继续保持运行处理请求,为保持服务器性能,将继续处理请求的线程优先级调低。   

                           3,在需要较长时间处理的请求处理完后,指示浏览器请求更新。     由于浏览器不维护与服务器之间的连接,服务器需要主动将结果发送给浏览器。     所以使用Referer响应报头,指示浏览器请求更新。

    五,使用Servlet生成图像和文字(响应报头Content-Type的应用)  

                (1),把图像文件写入磁盘并提供连接。注意写在您的web服务器目录树下(不是在服务器磁盘的任何地方都行)。   

                           在一些servlet引擎设置中,servlet的目录不能通过web server进入,只能通过servlet引擎。   也就是说您不能通过http:// URL登录,您可以向您的servlet输出的HTML传送IMG标签,或传送HTTP重新定位来让浏览器直接下载图象。     

    (CookieDetector (http://www.purpletech.com/code/CookieDetector.html) has an example, with source code, of sending a redirect.)     (CookieDetector (http://www.purpletech.com/code/CookieDetector.html)   有一个例子,有传送重新定位源代码。    图象可以被保存在浏览器的cache中,当再次请求时不必重新运行servlet,因此减轻了服务器的负担。     

                           图象不能从磁盘中删除,因此您必须写一段程序来定期清理图象目录,或进入目录 后用手工删除。(或买一张大点的硬盘)

                 (2),用Java 2 JPEGCodec类,或Acme Labs' GIFEncoder类将Java Graphics 转换成图象文件或二进制流。   

                          在<img>的src属性中调用实现上述功能的 Servlet并传递相关的参数,如背景图片路径、输出文字、文字输出的位置、字体、大小等,   由该Servlet进行图文处理,并返回处理后的图像数据,从而在网页上显示出加上文字的图像。    这个原理也是实现将数据库中的图像数据显示到网页上所用的原理。

       实现方法:   

            1,设置Content-Type响应报头为“images/jpeg”或“image/gif”或其他图片类型的报头。    

                     使用HttpServletResponse的setContentType方法设置。必须在返回实际的内容之前指定相关的报头。    

             2,获取原始的输出流。   

                     使用ServletResponse接口的getOutputSteam方法。    注意:request的getOutputStream和getWriter不能同时使用 也不能重复调用。前者为输出流后者为打印流!  

             3,获取图片的真实路径,封装为File对象。    

                      使用ServletContext接口的getRealPath方法指定虚拟路径,把虚拟路径映射为真实路径。    File类   

             4,获取二进制文件流。

                   图片大多数是二进制数据,所以使用字节输入流读入图片文件的。使用FileInputSteam类。   

              5,创建图片在程序内的缓冲对象:BufferedImage对象。   

                     通过构造函数创建一个BufferedImage对象。给出宽度,高度,以及由BufferedImage类中定义的常量所定义的图像类型。            

                     **可以在BufferedImage上绘制内容。调用图像的getGraphics方法,将得到的Graphics对象转换成Graphics2D,使用Graphics2D 来进行绘画操作。     

                 6,对图片进行解编输入码输出处理的二种方法。      

                     【1】,使用专门的API处理jpg图片或gif图片:读入文件解码输入,放入BufferedImage缓冲对象后编码输出。    

                           JPG和GIF图片文件可以使用com.sun.image.codec.jpeg.JPEGImageDecoder类和Acme Labs的GIFEncoder类。

                         对输入流数据进行解码后输入       

                                 JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(二进制文件流)方法 返回将读入的二进制文件流按jpg图片格式进行解码的解码器对象。  

                          图片缓冲对象临时存储解码图片       

                                  BufferedImage image = decoder.decodeAsBufferedImage()方法将解码后的图片放入BufferedImage缓冲对象 中。                  

                          对输出流数据进行编码后输出        

                                 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(输出流)方法 返回 jpg格式图片的编码器对象。

                           对输出流进行编码器的封装。        

                                 encoder.encode(BufferedImage缓冲对象),将BufferedImage缓冲对象进行编码后让输出流输出。  

    1. package com.qu.servlet.responseHeaders.contentType;  
    2.   
    3.   
    4.   
    5.   
    6.   
    7. import java.awt.Color;  
    8.   
    9. import java.awt.Font;  
    10.   
    11. import java.awt.Graphics;  
    12.   
    13.   
    14.   
    15. import java.awt.image.*;  
    16.   
    17. import java.io.File;  
    18.   
    19. import java.io.FileInputStream;  
    20.   
    21. import java.io.IOException;  
    22.   
    23. import java.io.InputStream;  
    24.   
    25. import javax.servlet.ServletConfig;  
    26.   
    27. import javax.servlet.ServletException;  
    28.   
    29. import javax.servlet.ServletOutputStream;  
    30.   
    31. import javax.servlet.http.HttpServlet;  
    32.   
    33. import javax.servlet.http.HttpServletRequest;  
    34.   
    35. import javax.servlet.http.HttpServletResponse;  
    36.   
    37.   
    38.   
    39. import com.sun.image.codec.jpeg.*;  
    40.   
    41.   
    42.   
    43. public class JpegImageServlet extends HttpServlet {  
    44.   
    45.       
    46.   
    47.     private String text = "";               //要嵌的文字  
    48.   
    49.     private String imagePath = "";          //被嵌的图片的虚拟路径  
    50.   
    51.     private int x = 0;                      //坐标  
    52.   
    53.     private int y = 0;  
    54.   
    55.     private String fontColor = "";          //字体颜色  
    56.   
    57.     private int fontSize = 0;               //字体大小  
    58.   
    59.     private String fontStyle = "";          //字体风格(斜体,粗体等)  
    60.   
    61.     private String fontName = "";           //字体名称  
    62.   
    63.     private String realPath;                //图片绝对路径  
    64.   
    65.        
    66.   
    67.     public JpegImageServlet() {  
    68.   
    69.         super();  
    70.   
    71.     }  
    72.   
    73.   
    74.   
    75.     /* (non-Javadoc) 
    76.  
    77.      * @see javax.servlet.GenericServlet#destroy() 
    78.  
    79.      */  
    80.   
    81.     @Override  
    82.   
    83.     public void destroy() {  
    84.   
    85.         super.destroy();  
    86.   
    87.     }  
    88.   
    89.   
    90.   
    91.     /* (non-Javadoc) 
    92.  
    93.      * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig) 
    94.  
    95.      */  
    96.   
    97.     @Override  
    98.   
    99.     public void init(ServletConfig config) throws ServletException {  
    100.   
    101.         System.out.println("11111111111");  
    102.   
    103.         text = this.getStrParameter(config,"text","");  
    104.   
    105.         imagePath = this.getStrParameter(config,"imagePath","");  
    106.   
    107.         x = this.getIntParameter(config,"x",0);  
    108.   
    109.         y = this.getIntParameter(config,"y",0);  
    110.   
    111.         fontColor = this.getStrParameter(config,"fontColor","");  
    112.   
    113.         fontSize = this.getIntParameter(config,"fontSize",16);  
    114.   
    115.         fontStyle = this.getStrParameter(config,"fontStyle","'");  
    116.   
    117.         fontName = this.getStrParameter(config,"fontName","");  
    118.   
    119.         realPath = config.getServletContext().getRealPath(imagePath);  
    120.   
    121.          
    122.   
    123.     }  
    124.   
    125.   
    126.   
    127.     /* (non-Javadoc) 
    128.  
    129.      * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) 
    130.  
    131.      */  
    132.   
    133.     @Override  
    134.   
    135.     protected void doGet(HttpServletRequest request, HttpServletResponse response)  
    136.   
    137.             throws ServletException, IOException {  
    138.   
    139.         /*请求处理*/  
    140.   
    141.         request.setCharacterEncoding("gb2312");  
    142.   
    143.           
    144.   
    145.         /*响应处理*/  
    146.   
    147.         response.setContentType("image/jpeg; charset=gb2312");  
    148.   
    149.           
    150.   
    151.         ServletOutputStream output = response.getOutputStream();  
    152.   
    153.           
    154.   
    155.         File imageFile = new File(realPath);  
    156.   
    157.         InputStream input = new FileInputStream(imageFile);  
    158.   
    159.       
    160.   
    161.         JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(input);  
    162.   
    163.         BufferedImage bufimg = decoder.decodeAsBufferedImage();  
    164.   
    165.         /**/  
    166.   
    167.         Graphics g = bufimg.createGraphics();  
    168.   
    169.       
    170.   
    171.         g.setColor(Color.white);//设置颜色  
    172.   
    173.         Font mFont = new Font(fontName,Font.PLAIN,fontSize);//设置字体为默认字体  
    174.   
    175.         if(fontStyle.equalsIgnoreCase("italic")) {  
    176.   
    177.             mFont=new Font(fontName,Font.ITALIC,fontSize);  
    178.   
    179.         }  
    180.   
    181.         if(fontStyle.equalsIgnoreCase("bold")) {  
    182.   
    183.             mFont=new Font(fontName,Font.BOLD,fontSize);  
    184.   
    185.         }  
    186.   
    187.         if(fontStyle.equalsIgnoreCase("plain")){   
    188.   
    189.             mFont=new Font(fontName,Font.PLAIN,fontSize);  
    190.   
    191.         }  
    192.   
    193.         g.setFont(mFont);   
    194.   
    195.         g.drawString(text,x,y);//输出文字  
    196.   
    197.          
    198.   
    199.        System.out.println("33333");  
    200.   
    201.         JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);  
    202.   
    203.         encoder.encode(bufimg);  
    204.   
    205.   
    206.   
    207.         input.close();  
    208.   
    209.         output.close();  
    210.   
    211.           
    212.   
    213.           
    214.   
    215.     }  
    216.   
    217.   
    218.   
    219.     /* (non-Javadoc) 
    220.  
    221.      * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) 
    222.  
    223.      */  
    224.   
    225.     @Override  
    226.   
    227.     protected void doPost(HttpServletRequest req, HttpServletResponse resp)  
    228.   
    229.             throws ServletException, IOException {  
    230.   
    231.         this.doGet(req, resp);  
    232.   
    233.     }  
    234.   
    235.       
    236.   
    237.     public String getStrParameter(ServletConfig config, String parameter, String defaultValue){  
    238.   
    239.         String paraValue = config.getInitParameter(parameter);  
    240.   
    241.           
    242.   
    243.         if (paraValue != null && !paraValue.equals("")){  
    244.   
    245.             //需要的话将参数值转码  
    246.   
    247.         }else{  
    248.   
    249.             paraValue = defaultValue;  
    250.   
    251.         }  
    252.   
    253.         return paraValue;  
    254.   
    255.     }  
    256.   
    257.       
    258.   
    259.     public int getIntParameter(ServletConfig config, String parameter, int defaultValue){  
    260.   
    261.         int paraValue;  
    262.   
    263.         String temp = config.getInitParameter(parameter);  
    264.   
    265.           
    266.   
    267.         if (temp != null && !temp.equals("")){  
    268.   
    269.             paraValue = Integer.parseInt(temp);  
    270.   
    271.         }else{  
    272.   
    273.             paraValue = defaultValue;  
    274.   
    275.         }  
    276.   
    277.           
    278.   
    279.         return paraValue;  
    280.   
    281.     }  
    282.   
    283. }  

               

                       【2】,使用javax.imageio.ImageIO类对响应报头中指定的图片类型进行解编码处理。     使用ImageIO类的write方法,该方法根据不同用途进行了重载。    

                                        使用ImageIO类的Read方法读入一个输入流获得一个BufferedImage对象。

                                        使用ImageIO类的write方法,该方法进行了重载。                                   

                                      使用ImageIO类的write,传递一个BufferedImage缓冲对象(进行了自定义的绘图操作和缓冲了读入的图片),指定一个String的图片格式类型,一个输出流对象。

    1. package com.qu.servlet.responseHeaders.contentType;  
    2.   
    3.   
    4.   
    5. import java.awt.Color;  
    6.   
    7. import java.awt.Font;  
    8.   
    9. import java.awt.Graphics;  
    10.   
    11. import java.awt.image.BufferedImage;  
    12.   
    13. import java.io.File;  
    14.   
    15. import java.io.FileInputStream;  
    16.   
    17. import java.io.IOException;  
    18.   
    19. import javax.imageio.ImageIO;  
    20.   
    21. import javax.servlet.ServletConfig;  
    22.   
    23. import javax.servlet.ServletException;  
    24.   
    25. import javax.servlet.ServletOutputStream;  
    26.   
    27. import javax.servlet.http.HttpServlet;  
    28.   
    29. import javax.servlet.http.HttpServletRequest;  
    30.   
    31. import javax.servlet.http.HttpServletResponse;  
    32.   
    33.   
    34.   
    35.   
    36.   
    37. public class ImageIOServlet extends HttpServlet {  
    38.   
    39.   
    40.   
    41.       
    42.   
    43.     private String text = "";               //要嵌的文字  
    44.   
    45.     private String imagePath = "";          //被嵌的图片的虚拟路径  
    46.   
    47.     private int x = 0;                      //坐标  
    48.   
    49.     private int y = 0;  
    50.   
    51.     private String fontColor = "";          //字体颜色  
    52.   
    53.     private int fontSize = 0;               //字体大小  
    54.   
    55.     private String fontStyle = "";          //字体风格(斜体,粗体等)  
    56.   
    57.     private String fontName = "";           //字体名称  
    58.   
    59.     private String realPath;                //图片绝对路径  
    60.   
    61.        
    62.   
    63.     public ImageIOServlet() {  
    64.   
    65.         super();  
    66.   
    67.     }  
    68.   
    69.   
    70.   
    71.     /* (non-Javadoc) 
    72.  
    73.      * @see javax.servlet.GenericServlet#destroy() 
    74.  
    75.      */  
    76.   
    77.     @Override  
    78.   
    79.     public void destroy() {  
    80.   
    81.         super.destroy();  
    82.   
    83.     }  
    84.   
    85.   
    86.   
    87.     /* (non-Javadoc) 
    88.  
    89.      * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig) 
    90.  
    91.      */  
    92.   
    93.     @Override  
    94.   
    95.       
    96.   
    97.     public void init(ServletConfig config) throws ServletException {  
    98.   
    99.         System.out.println("11111111111");  
    100.   
    101.         text = this.getStrParameter(config,"text","");  
    102.   
    103.         imagePath = this.getStrParameter(config,"imagePath","");  
    104.   
    105.         x = this.getIntParameter(config,"x",0);  
    106.   
    107.         y = this.getIntParameter(config,"y",0);  
    108.   
    109.         fontColor = this.getStrParameter(config,"fontColor","");  
    110.   
    111.         fontSize = this.getIntParameter(config,"fontSize",16);  
    112.   
    113.         fontStyle = this.getStrParameter(config,"fontStyle","'");  
    114.   
    115.         fontName = this.getStrParameter(config,"fontName","");  
    116.   
    117.         realPath = config.getServletContext().getRealPath(imagePath);  
    118.   
    119.        System.out.println(realPath);  
    120.   
    121.     }  
    122.   
    123.   
    124.   
    125.     /* (non-Javadoc) 
    126.  
    127.      * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) 
    128.  
    129.      */  
    130.   
    131.     @Override  
    132.   
    133.     protected void doGet(HttpServletRequest request, HttpServletResponse response)  
    134.   
    135.             throws ServletException, IOException {  
    136.   
    137.         /*请求处理*/  
    138.   
    139.         request.setCharacterEncoding("gb2312");  
    140.   
    141.             
    142.   
    143.         /*响应处理*/  
    144.   
    145.         response.setContentType("image/gif; charset=gb2312");  
    146.   
    147.           
    148.   
    149.         ServletOutputStream output = response.getOutputStream();  
    150.   
    151.           
    152.   
    153.         File imageFile = new File(realPath);  
    154.   
    155.           
    156.   
    157.         FileInputStream imgInput = new FileInputStream(imageFile);  
    158.   
    159.           
    160.   
    161.         //Image img = ImageIO.read(imgInput);  
    162.   
    163.           
    164.   
    165.         BufferedImage bimg = ImageIO.read(imgInput);  
    166.   
    167.         /**/  
    168.   
    169.         Graphics g = bimg.getGraphics();  
    170.   
    171.           
    172.   
    173.         g.setColor(Color.red);//设置颜色  
    174.   
    175.         Font mFont = new Font(fontName,Font.PLAIN,fontSize);//设置字体为默认字体  
    176.   
    177.         if(fontStyle.equalsIgnoreCase("italic")) {  
    178.   
    179.             mFont=new Font(fontName,Font.ITALIC,fontSize);  
    180.   
    181.         }  
    182.   
    183.         if(fontStyle.equalsIgnoreCase("bold")) {  
    184.   
    185.             mFont=new Font(fontName,Font.BOLD,fontSize);  
    186.   
    187.         }  
    188.   
    189.         if(fontStyle.equalsIgnoreCase("plain")){   
    190.   
    191.             mFont=new Font(fontName,Font.PLAIN,fontSize);  
    192.   
    193.         }  
    194.   
    195.         g.setFont(mFont);   
    196.   
    197.         g.drawString(text,x,y);//输出文字  
    198.   
    199.           
    200.   
    201.         ImageIO.write(bimg, "gif", output);  
    202.   
    203.       
    204.   
    205.         bimg.flush();  
    206.   
    207.         imgInput.close();  
    208.   
    209.         output.close();  
    210.   
    211.           
    212.   
    213.     }  
    214.   
    215.   
    216.   
    217.     /* (non-Javadoc) 
    218.  
    219.      * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) 
    220.  
    221.      */  
    222.   
    223.     @Override  
    224.   
    225.     protected void doPost(HttpServletRequest req, HttpServletResponse resp)  
    226.   
    227.             throws ServletException, IOException {  
    228.   
    229.         this.doGet(req, resp);  
    230.   
    231.     }  
    232.   
    233.       
    234.   
    235.     public String getStrParameter(ServletConfig config, String parameter, String defaultValue){  
    236.   
    237.         String paraValue = config.getInitParameter(parameter);  
    238.   
    239.           
    240.   
    241.         if (paraValue != null && !paraValue.equals("")){  
    242.   
    243.             //需要的话将参数值转码  
    244.   
    245.         }else{  
    246.   
    247.             paraValue = defaultValue;  
    248.   
    249.         }  
    250.   
    251.         return paraValue;  
    252.   
    253.     }  
    254.   
    255.       
    256.   
    257.     public int getIntParameter(ServletConfig config, String parameter, int defaultValue){  
    258.   
    259.         int paraValue;  
    260.   
    261.         String temp = config.getInitParameter(parameter);  
    262.   
    263.           
    264.   
    265.         if (temp != null && !temp.equals("")){  
    266.   
    267.             paraValue = Integer.parseInt(temp);  
    268.   
    269.         }else{  
    270.   
    271.             paraValue = defaultValue;  
    272.   
    273.         }  
    274.   
    275.           
    276.   
    277.         return paraValue;  
    278.   
    279.     }  
    280.   
    281. }  

       

                         【3】,不使用解码和编码来处理输入流和输出流。直接BufferedOutputStream输出缓冲流,输出BufferedImage缓冲对象。  

    1. response.setContentType("images/jpeg"); //设置响应报头       
    2.   
    3.   
    4.   
    5. OutputStream output = response.getOutputStream();//得到输出流       
    6.   
    7.   
    8.   
    9. ServletContext context = getServletContext();//得到上下文对象       
    10.   
    11.   
    12.   
    13. InputStream imageIn=context.getResourceAsStream(imagePath);//文件流           
    14.   
    15.   
    16.   
    17. BufferedInputStream bis=new BufferedInputStream(imageIn);//使用输入流初始化输入缓冲流。      
    18.   
    19.   
    20.   
    21.  BufferedOutputStream bos=new BufferedOutputStream(output);//使用输出流构造输出缓冲流。       
    22.   
    23.   
    24.   
    25. byte data[]=new byte[4096];//缓冲字节数        
    26.   
    27.   
    28.   
    29. int size= bis.read(data); //初始化读入       
    30.   
    31.   
    32.   
    33. while (size!=-1)        
    34.   
    35.   
    36.   
    37. {           
    38.   
    39.   
    40.   
    41.               bos.write(data,0,size);//输出读入的字节数数据        
    42.   
    43.   
    44.   
    45.               size=bis.read(data);//读取字节数数据       
    46.   
    47.   
    48.   
    49. }//end while        
    50.   
    51.   
    52.   
    53. bis.close();//关闭输入缓冲流        
    54.   
    55.   
    56.   
    57. bos.flush();//清空输出缓冲流                
    58.   
    59.   
    60.   
    61. bos.close();         
    62.   
    63.   
    64.   
    65. output.close();//关闭输出流  

       

    WEB.XML

      1. <?xml version="1.0" encoding="UTF-8"?>  
      2.   
      3. <web-app version="2.4"   
      4.   
      5.     xmlns="http://java.sun.com/xml/ns/j2ee"   
      6.   
      7.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
      8.   
      9.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   
      10.   
      11.     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
      12.   
      13.   <welcome-file-list>  
      14.   
      15.     <welcome-file>imageIO</welcome-file>  
      16.   
      17.   </welcome-file-list>  
      18.   
      19.   <!-- Servlet start -->  
      20.   
      21.   <servlet>  
      22.   
      23.     <servlet-name>ExcelServlet</servlet-name>  
      24.   
      25.     <servlet-class>com.qu.servlet.responseHeaders.contentType.ExcelServlet</servlet-class>  
      26.   
      27.   </servlet>  
      28.   
      29.   <servlet>  
      30.   
      31.     <servlet-name>JpegImageServlet</servlet-name>  
      32.   
      33.     <servlet-class>com.qu.servlet.responseHeaders.contentType.JpegImageServlet</servlet-class>  
      34.   
      35.     <init-param>  
      36.   
      37.         <param-name>text</param-name>  
      38.   
      39.         <param-value>新闻</param-value>  
      40.   
      41.     </init-param>  
      42.   
      43.     <init-param>  
      44.   
      45.         <param-name>imagePath</param-name>  
      46.   
      47.         <param-value>/images/bg.jpg</param-value>  
      48.   
      49.     </init-param>  
      50.   
      51.     <init-param>    
      52.   
      53.         <param-name>x</param-name>  
      54.   
      55.         <param-value>20</param-value>    
      56.   
      57.     </init-param>       
      58.   
      59.     <init-param>    
      60.   
      61.         <param-name>y</param-name>  
      62.   
      63.         <param-value>20</param-value>    
      64.   
      65.     </init-param>       
      66.   
      67.     <init-param>  
      68.   
      69.         <param-name>fontColor</param-name>  
      70.   
      71.         <param-value>red</param-value>  
      72.   
      73.     </init-param>   
      74.   
      75.     <init-param>    
      76.   
      77.         <param-name>fontSize</param-name>  
      78.   
      79.         <param-value>16</param-value>  
      80.   
      81.     </init-param>  
      82.   
      83.     <init-param>    
      84.   
      85.         <param-name>fontStyle</param-name>  
      86.   
      87.         <param-value>bold</param-value>  
      88.   
      89.     </init-param>  
      90.   
      91.     <init-param>    
      92.   
      93.         <param-name>fontName</param-name>  
      94.   
      95.         <param-value>宋体</param-value>                 
      96.   
      97.     </init-param>  
      98.   
      99.   </servlet>  
      100.   
      101.   <servlet>  
      102.   
      103.     <servlet-name>ImageIOServlet</servlet-name>  
      104.   
      105.     <servlet-class>com.qu.servlet.responseHeaders.contentType.ImageIOServlet</servlet-class>  
      106.   
      107.     <init-param>  
      108.   
      109.         <param-name>text</param-name>  
      110.   
      111.         <param-value>漫画美女!</param-value>  
      112.   
      113.     </init-param>  
      114.   
      115.     <init-param>  
      116.   
      117.         <param-name>imagePath</param-name>  
      118.   
      119.         <param-value>/images/MM.gif</param-value>  
      120.   
      121.     </init-param>  
      122.   
      123.     <init-param>    
      124.   
      125.         <param-name>x</param-name>  
      126.   
      127.         <param-value>50</param-value>    
      128.   
      129.     </init-param>       
      130.   
      131.     <init-param>    
      132.   
      133.         <param-name>y</param-name>  
      134.   
      135.         <param-value>30</param-value>    
      136.   
      137.     </init-param>       
      138.   
      139.     <init-param>  
      140.   
      141.         <param-name>fontColor</param-name>  
      142.   
      143.         <param-value>black</param-value>  
      144.   
      145.     </init-param>   
      146.   
      147.     <init-param>    
      148.   
      149.         <param-name>fontSize</param-name>  
      150.   
      151.         <param-value>20</param-value>  
      152.   
      153.     </init-param>  
      154.   
      155.     <init-param>    
      156.   
      157.         <param-name>fontStyle</param-name>  
      158.   
      159.         <param-value>bold</param-value>  
      160.   
      161.     </init-param>  
      162.   
      163.     <init-param>    
      164.   
      165.         <param-name>fontName</param-name>  
      166.   
      167.         <param-value>隶书</param-value>                 
      168.   
      169.     </init-param>   
      170.   
      171.   </servlet>  
      172.   
      173.   <!-- servlet end -->  
      174.   
      175.   <!-- servlet mapping start -->  
      176.   
      177.   <servlet-mapping>  
      178.   
      179.     <servlet-name>ExcelServlet</servlet-name>  
      180.   
      181.     <url-pattern>/excel</url-pattern>  
      182.   
      183.   </servlet-mapping>  
      184.   
      185.   <servlet-mapping>  
      186.   
      187.     <servlet-name>JpegImageServlet</servlet-name>  
      188.   
      189.     <url-pattern>/jpegImage</url-pattern>  
      190.   
      191.   </servlet-mapping>  
      192.   
      193.   <servlet-mapping>  
      194.   
      195.     <servlet-name>ImageIOServlet</servlet-name>  
      196.   
      197.     <url-pattern>/imageIO</url-pattern>  
      198.   
      199.   </servlet-mapping>  
      200.   
      201.   <!-- servlet mapping end -->  
      202.   
      203. </web-app
  • 相关阅读:
    CSS实现点击改变元素背景色
    php三种方法从控制结构或脚本中跳出
    如何关闭运行在某端口的的进程,例如 :8080端口
    Webpack简易入门教程
    git add -A 和 git add . 的区别
    怎样把已经做好的网页传到网上去?
    jquery源码之事件系统-- jQuery.event
    jquery源码之缓存系统--$.data
    jquery源码之延迟对象--Deferred
    jquery源码之低调的回调函数队列--Callbacks
  • 原文地址:https://www.cnblogs.com/zyn1990/p/3873141.html
Copyright © 2011-2022 走看看