1. 确认提交代码.
2. 先构建service,后构建war。(构建完了自动发布到服务器)若访问不了,重新构建,知道能够访问了。http://172.28.17.85:8080/itop-war/user/
有问题时可通过secureCRT查看172.28.17.85服务器端 tomcat日志:
有问题没思路时首先看错误日志
ops@copy:/var/lib/tomcat7$ cd logs
ops@copy:/var/lib/tomcat7/logs$ dir
localhost_access_log.2016-12-02.txt
ops@copy:/var/lib/tomcat7/logs$ tail -n 100 itop-war.log
config.properties等资源文件并没有打包到war包,发布时需要单独在linux服务器上配置。
图片放在服务器的位置:
/usr/local/pics
简单测试form表单的springmvc的响应:
文件要html格式的,jsp不行
当选中了传输的文件时,前台逻辑控制显示ffile属性。否则报错:string not not convert to MultipartFile
<html>
<body><form id="p" action="http://localhost:8090/itop-war/user/update"
method="post"
enctype="multipart/form-data">
<input type="hidden" name="id" value="181" />
file: <input type="file" name="ffile"/><br>
idcardno: <input type="text" name="idcardno"/><br>
<input type="submit" value="ok" />
</form>
</body>
</html>
//后台代码
@ResponseBody
public JSONObject insert(Employee record, @RequestParam(value="ffile",required=false) MultipartFile ffile,
HttpServletRequest request) {
// 图片上传处理
if (ffile != null && !ffile.isEmpty()) {
String dir = Cfg.cfg.getString("server.dir"); // 设定文件保存的目录
String orName = ffile.getOriginalFilename();
int index = orName.lastIndexOf(Commons.DIAN);
String filename = record.getIdcardno() + orName.substring(index); // 文件名用上传的身份证号
try {
FileUtils.writeByteArrayToFile(new File(dir, filename),
ffile.getBytes());
} catch (IOException e) {
log.error("upload fail:" + e.getMessage());
}
record.setPath(filename); // 设置图片所在路径
}else{
record.setPath("");
}
在自己的电脑上使用别人的前台开发环境:
修改文件 C:\Windows\System32\drivers\etc\hosts
172.28.11.10 www.lewis.com (对方的ip)