(教學)在Ubuntu裡建立Apache with Tomcat 服務-3

前二篇資料(教學)在Ubuntu裡建立Apache with Tomcat 服務-2    (教學)在Ubuntu裡建立Apache with Tomcat 服務-1

讓Apache Server與Tomcat Server做溝通

使Apache支援JSP及測試ImageMagick及JMagick是否可用

1.設定apache使用apj與tomcat做溝通,把所有內容向tomcat送

#sudo vi /etc/apache2/sites-available/default 

在<VirtualHost *:80></VirtualHost>tag內增加

 LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so 
 LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so 
 LoadModule proxy_connect_module /usr/lib/apache2/modules/mod_proxy_conn$ 
 LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so 
 ProxyPass / ajp://127.0.0.1:8009/ 
 ProxyPassReverse / ajp://127.0.0.1:8009/

2.重新啟動tomcat及apache

#sudo /etc/init.d/tomcat5 restart 
#sudo /etc/init.d/apache2 restart 

測試http://localhost/是否跟http://localhost:8080/一樣

一樣的話就是成功了!

3.測試jmagick是否可用

#sudo vi /etc/tomcat5/webapps/ROOT/testimage.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>Insert title here</title> 
</head> 
<body> 
<%
String strAbsPath=new java.io.File(application.getRealPath(request.getRequestURI())).getParent(); 
java.io.File f = new java.io.File(strAbsPath+"/test.jpg"); 
System.out.println(strAbsPath+"/test.jpg"); 
if(!f.exists()) 
{ 
    java.net.URL url = new java.net.URL("http://service.wakema.com.tw/img/huodong/zip/82X117/574-t257_m_image.jpg"); 
    java.net.URLConnection URLConn = (java.net.HttpURLConnection)url.openConnection(); 
    java.io.BufferedInputStream bs = null; 
    try 
    { 
        bs = new java.io.BufferedInputStream(URLConn.getInputStream()); 
        java.awt.image.BufferedImage bimg = javax.imageio.ImageIO.read(bs); 
        javax.imageio.ImageIO.write(bimg,"jpg",f); 
        bs.close(); 
    }catch(java.io.IOException e) 
    { 
        throw e; 
    } 
    finally 
    { 
        try 
        { 
            if(bs!=null) 
            { 
                bs.close(); 
                bs = null; 
            } 
        }catch(java.io.IOException ex) 
        { 
        } 
    } 
} 
if (System.getProperty("jmagick.systemclassloader") == null) { 
    System.setProperty("jmagick.systemclassloader", "no"); 
  } 
  magick.ImageInfo info = new magick.ImageInfo(strAbsPath+"/test.jpg"); 
  magick.MagickImage image = new magick.MagickImage(info);

//resize image

magick.MagickImage scaleImg = image.scaleImage(65, 46); 
scaleImg.setFileName(strAbsPath+"/test2.jpg"); 
scaleImg.writeImage(info); 
%><img src="test.jpg"><br/> 
<img src="test2.jpg"> 
</body> 
</html>

http://localhost/testimage.jsp

如果可以看到一個大圖一個小圖那就是沒問題了

發表迴響