1、項目搭建
在github上下載spring-boot源碼,
spring-boot-1.3.2.RELEASE\spring-boot-samples\spring-boot-sample-web-jsp
這個項目就是spring boot 對jsp的支持
2、項目部署
由于是spring boot對jsp的支持,jar啟動方式只在本地有效,在服務器上無效,所以部署時還是打成war包,跟傳統的web項目一樣,放在tomcat中運行,本項目用的是 jdk8+tomcat8
(1)tomcat中修改端口號,配置jdk路徑
(2)啟動
3、幾個錯誤
(1)tomcat啟動報錯,can not load amd64
jdk用了32位和tomcat用了64位,版本不匹配
(2)linux上有多個jdk,多個tomcat,要為自己的tomcat指定jdk版本
tomat路徑/bin/catalina.out, 在第一行添加:
export JAVA_HOME=/usr/java8
(3)jstl scope配置錯誤,設置成了provided,導致WEB-INF/lib包中沒有 jstl-1.2.jar包
[java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.classes.views.index_jsp]
參考鏈接:http://www.cnblogs.com/bruceChan0018/p/5851828.html
正確配置如下:
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
4、知識點總結
(1)測試環境是aix6.1,unix下 tar.gz 解壓命令跟linux下不同
linux解壓tar.gz為:tar -zvxf file.tar.gz
unix 命令
壓縮 # tar cvf - folder | gzip > filename.tar.gz
解壓 # gunzip -c filename.tar.gz | tar -xvf -
(2)關閉端口
#netstat -Aan|grep 23
f1000200019ce398 tcp 0 0 *.23 *.* LISTEN
#rmsock f1000200019ce398 tcpcb
The socket 0x19ce008 is being held by proccess 185006 (inetd).
#kill -9 185006
(3)java web項目 把文件放到于根目錄平行的以用戶名命名的文件夾下
不能把文件放在項目的resource目錄下,因為war更換,重啟等會導致文件丟失
- 獲取web項目根路徑,即發布到tomcat的webapp下的項目名
- 新建文件夾
- 獲取輸出流,寫文件
// 項目根路徑
String path = session.getServletContext().getRealPath("/");
File pathFile = new File(path + "../" + user.getRealname());
pathFile.mkdir();
logger.info("創建一個以用戶名為真實名字的文件夾, pathFile:" + pathFile.getPath());
File saveFile = new File(pathFile + "/" + fileNameAll);
inputStream = (ByteArrayInputStream) multiReq.getFile("file").getInputStream();
outputStream = new FileOutputStream(saveFile);
........