1. 图片回显:
不能跟其他类的字段一样返回显示,只能通过response显示图片。每次根据id获取图片显示。
@RequestMapping(value = "/image/get")
public void getImage(int id, HttpServletRequest request,
HttpServletResponse response) {
FileInputStream fis = null;
response.setContentType("image/gif");
...
try {
OutputStream out = response.getOutputStream(); //通过response显示图片
File file = new File(fullpath); //服务器上图片的路径
fis = new FileInputStream(file);
byte[] b = new byte[fis.available()];
fis.read(b);
out.write(b);
out.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
2. 设置服务器pics目录的权限为777。
3. pics同级位置增加autoDeploy目录,包含autoDeploy.sh:
#!/bin/bash
password=21ops.com
basepath=$(cd `dirname $0`; pwd)
model=$1
version=$2
hudsonURL="http://172.28.11.133:9080/hudson/job"
#catalina_home="/usr/share/tomcat7"
warName="$model.war"
webapp="/var/lib/tomcat7/webapps"
echo "============================================">>$basepath/autoDeploy.log
if [ -z $version ];then
version="lastBuild";
fi
logURL="$hudsonURL/$model/$version/consoleText"
consoleLog="$basepath/consoleLog_$$.log"
wget -O $consoleLog $logURL 1>/dev/null 2>&1
downloadURL=""
while read LINE
do
LINE=`echo $LINE | sed 's/[[:space:]]//g'`
echo "$LINE" | grep -q "^Uploading.*war$"
if [ 0 -eq $? ];then
downloadURL=`echo $LINE | sed 's/^Uploading://g'`
break
fi
done < $consoleLog
rm -fr $consoleLog
echo "URL:$downloadURL">>$basepath/autoDeploy.log
wget -O $basepath/package/$warName $downloadURL
echo "download file finished!">>$basepath/autoDeploy.log
echo "stop tomcat">>$basepath/autoDeploy.log
#$catalina_home/bin/shutdown.sh
echo $password | sudo -S service tomcat7 stop
echo "copy $warName to $webapp">>$basepath/autoDeploy.log
echo $password | sudo -S rm -fr "$webapp/$model"
mv "$basepath/package/$warName" "$webapp"
"autoDeploy.sh" 56L, 1514C