Skip to content

Commit af6186e

Browse files
committed
fix deploy in web container problem ,adding contextpath to every url
1 parent 5651a59 commit af6186e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+327
-272
lines changed

pom.xml

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.2.4 http://maven.apache.org/maven-v4_0_0.xsd">
33

44
<artifactId>com.giit.www.orderbook</artifactId>
55
<groupId>core</groupId>
@@ -10,6 +10,7 @@
1010
<name>giit</name>
1111
<url>http://maven.apache.org</url>
1212

13+
1314
<dependencies>
1415
<dependency>
1516
<groupId>junit</groupId>
@@ -75,31 +76,31 @@
7576
<dependency>
7677
<groupId>org.springframework</groupId>
7778
<artifactId>spring-test</artifactId>
78-
<version>4.0.0.RELEASE</version>
79+
<version>4.2.4.RELEASE</version>
7980
<scope>test</scope>
8081
</dependency>
8182
<dependency>
8283
<groupId>org.springframework</groupId>
8384
<artifactId>spring-context-support</artifactId>
84-
<version>4.0.0.RELEASE</version>
85+
<version>4.2.4.RELEASE</version>
8586
</dependency>
8687

8788
<dependency>
8889
<groupId>org.springframework</groupId>
8990
<artifactId>spring-jdbc</artifactId>
90-
<version>4.0.0.RELEASE</version>
91+
<version>4.2.4.RELEASE</version>
9192
</dependency>
9293

9394
<dependency>
9495
<groupId>org.springframework</groupId>
9596
<artifactId>spring-tx</artifactId>
96-
<version>4.0.0.RELEASE</version>
97+
<version>4.2.4.RELEASE</version>
9798
</dependency>
9899

99100
<dependency>
100101
<groupId>org.springframework</groupId>
101102
<artifactId>spring-webmvc</artifactId>
102-
<version>4.0.0.RELEASE</version>
103+
<version>4.2.4.RELEASE</version>
103104
</dependency>
104105

105106

@@ -161,7 +162,7 @@
161162
<groupId>ognl</groupId>
162163
<artifactId>ognl</artifactId>
163164
<version>3.1.2</version>
164-
</dependency>
165+
</dependency>
165166
<dependency>
166167
<groupId>org.javassist</groupId>
167168
<artifactId>javassist</artifactId>
@@ -183,17 +184,42 @@
183184
<version>2.1</version>
184185
</dependency>
185186
<!--json parser-->
186-
<dependency>
187+
<dependency>
187188
<groupId>com.google.code.gson</groupId>
188189
<artifactId>gson</artifactId>
189190
<version>2.6</version>
190-
</dependency>
191+
</dependency>
192+
<!--file upload-->
193+
<dependency>
194+
<groupId>commons-fileupload</groupId>
195+
<artifactId>commons-fileupload</artifactId>
196+
<version>1.3.1</version>
197+
</dependency>
191198

192199
</dependencies>
193200

194201
<build>
195202
<finalName>giit</finalName>
196-
203+
<resources>
204+
<resource>
205+
<directory>src/main/resources</directory>
206+
<includes>
207+
<include>**/*.properties</include>
208+
<include>**/*.xml</include>
209+
<include>**/*.tld</include>
210+
</includes>
211+
<filtering>false</filtering>
212+
</resource>
213+
<resource>
214+
<directory>src/main/java</directory>
215+
<includes>
216+
<include>**/*.properties</include>
217+
<include>**/*.xml</include>
218+
<include>**/*.tld</include>
219+
</includes>
220+
<filtering>false</filtering>
221+
</resource>
222+
</resources>
197223
<plugins>
198224
<plugin>
199225
<groupId>org.apache.maven.plugins</groupId>
@@ -226,23 +252,20 @@
226252
<containerId>tomcat8x</containerId>
227253
<!-- 指定tomcat路径 -->
228254
<home>/home/c0de8ug/software/apache-tomcat-8.0.28</home>
255+
<timeout>300000</timeout>
229256
</container>
230257
<configuration>
231258
<type>existing</type>
232259
<!--指定tomcat路径 -->
233260
<home>/home/c0de8ug/software/apache-tomcat-8.0.28</home>
234-
<properties>
235-
<!-- 更改监听端口 -->
236-
<cargo.servlet.port>8888</cargo.servlet.port>
237-
</properties>
238261
</configuration>
239262
</configuration>
240263
<executions>
241264
<execution>
242-
<id>cargo-run</id>
265+
<id>cargo-start</id>
243266
<phase>install</phase>
244267
<goals>
245-
<goal>run</goal>
268+
<goal>start</goal>
246269
</goals>
247270
</execution>
248271
</executions>

src/main/java/com/giit/www/college/controller/OrderBookController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ public void update(@RequestBody ChangedItems changedItems, HttpSession session)
8383
public String audit(HttpSession session) {
8484
List<OrderBookReviewVo> orderBookReviewVoList = (List<OrderBookReviewVo>) session.getAttribute("notReviewedBookList");
8585
orderBookBiz.audit(orderBookReviewVoList);
86-
return "orderbook.do/orderbook_review.view";
86+
return "redirect:/orderbook.do/orderbook_review.view";
8787
}
8888
}

src/main/java/com/giit/www/college/controller/StudentController.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
import org.springframework.stereotype.Controller;
66
import org.springframework.ui.Model;
77
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.multipart.MultipartFile;
89

910
import javax.annotation.Resource;
11+
import javax.servlet.annotation.MultipartConfig;
12+
import java.io.IOException;
1013

1114
/**
1215
* Created by c0de8ug on 16-2-12.
@@ -36,16 +39,17 @@ public String studentUpdateView(Model m) {
3639

3740
return "/admin/college/student_update";
3841
}
42+
3943
@RequestMapping("add")
40-
public String add(Model m, Student student) {
41-
studentBiz.add(student);
42-
return "/student.do/student.view";
44+
public String add(Model m, MultipartFile pic, Student student) throws IOException {
45+
studentBiz.add(student,pic);
46+
return "redirect:/student.do/student.view";
4347
}
4448

4549
@RequestMapping("delete")
4650
public String delete(Model m, int studentId) {
4751
studentBiz.delete(studentId);
48-
return "/student.do/student.view";
52+
return "redirect:/student.do/student.view";
4953
}
5054

5155
}

src/main/java/com/giit/www/college/dao/StudentDao.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<result property="telephoneNumber" column="telephone_number"/>
1515
<result property="student_origin_base" column="studentOriginBase"/>
1616
<result property="gender" column="gender"/>
17-
<result property="photo" column="photo"/>
17+
<result property="picPath" column="pic_path"/>
1818
</resultMap>
1919
<select id="findAll" resultMap="student_map">
2020
SELECT * FROM student
@@ -24,7 +24,7 @@
2424
INSERT INTO student
2525
(
2626
student_id,student_name,id_card,year,class_name,
27-
telephone_number,student_origin_base,gender,photo
27+
telephone_number,student_origin_base,gender,pic_path
2828
)
2929
VALUES
3030
(
@@ -36,7 +36,7 @@
3636
#{telephoneNumber},
3737
#{studentOriginBase},
3838
#{gender},
39-
#{photo})
39+
#{picPath})
4040
</insert>
4141
<delete id="delete" parameterType="int">
4242
DELETE FROM student WHERE student_id = #{value}

src/main/java/com/giit/www/college/service/StudentBiz.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.giit.www.college.service;
22

33
import com.giit.www.entity.Student;
4+
import org.springframework.web.multipart.MultipartFile;
45

6+
import java.io.IOException;
57
import java.util.List;
68

79
/**
@@ -11,7 +13,7 @@
1113
public interface StudentBiz {
1214
public List<Student> studentView();
1315

14-
public void add(Student student);
16+
public void add(Student student, MultipartFile pic) throws IOException;
1517

1618
public void update(Student student);
1719

src/main/java/com/giit/www/college/service/impl/StudentBizImpl.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
import com.giit.www.college.service.StudentBiz;
55
import com.giit.www.entity.Student;
66
import org.springframework.stereotype.Service;
7+
import org.springframework.web.multipart.MultipartFile;
78

89
import javax.annotation.Resource;
10+
import java.io.File;
11+
import java.io.IOException;
912
import java.util.List;
13+
import java.util.UUID;
1014

1115
/**
1216
* Created by c0de8ug on 16-2-13.
@@ -20,7 +24,23 @@ public List<Student> studentView() {
2024
return studentDao.findAll();
2125
}
2226

23-
public void add(Student student) {
27+
public void add(Student student, MultipartFile pic) throws IOException {
28+
29+
if (pic.getSize() != 0) {
30+
String originalFilename = pic.getOriginalFilename();
31+
32+
String fileType = originalFilename.substring(originalFilename.lastIndexOf("."));
33+
String newFilename = UUID.randomUUID() + fileType;
34+
35+
//TODO 这里的路径分配应该放到环境变量
36+
String path = "/home/c0de8ug/software/apache-tomcat-8.0.28/pic/";
37+
38+
File dest = new File(path + newFilename);
39+
pic.transferTo(dest);
40+
41+
student.setPicPath(newFilename);
42+
}
43+
2444
studentDao.add(student);
2545
}
2646

src/main/java/com/giit/www/entity/Student.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Student {
1212
String telephoneNumber;
1313
String studentOriginBase;
1414
String gender;
15-
byte[] photo;
15+
String picPath;
1616

1717
public String getStudentId() {
1818
return studentId;
@@ -78,11 +78,11 @@ public void setGender(String gender) {
7878
this.gender = gender;
7979
}
8080

81-
public byte[] getPhoto() {
82-
return photo;
81+
public String getPicPath() {
82+
return picPath;
8383
}
8484

85-
public void setPhoto(byte[] photo) {
86-
this.photo = photo;
85+
public void setPicPath(String picPath) {
86+
this.picPath = picPath;
8787
}
8888
}

src/main/java/com/giit/www/system/controller/AccountController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public String profileView() {
2727
public String update(HttpSession session, String password) {
2828
String id = (String) session.getAttribute("username");
2929
accountBiz.updatePassword(id, password);
30-
return "";
30+
return "redirect:/account.do/profile.view";
3131
}
3232
}

src/main/java/com/giit/www/system/interceptor/LoginIntercepter.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Created by c0de8ug on 16-2-14.
1313
*/
1414
public class LoginIntercepter implements HandlerInterceptor {
15+
1516
@Override
1617
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
1718

@@ -27,13 +28,24 @@ public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletRespo
2728
return true;
2829
}
2930

30-
httpServletResponse.sendRedirect("/login.jsp");
31+
httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + "/login.jsp");
3132
return false;
3233
}
3334

3435
@Override
3536
public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
36-
37+
//
38+
//
39+
// String redirectStr = "redirect:";
40+
// int strLength = 9;
41+
//
42+
//
43+
// String path = modelAndView.getViewName();
44+
// if (path.indexOf(redirectStr) == 0) {
45+
// String temp = path.substring(strLength);
46+
//
47+
// modelAndView.setViewName(redirectStr + contextPath + temp);
48+
// }
3749
}
3850

3951
@Override

src/main/webapp/WEB-INF/dispatcher-servlet.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@
2424
class="org.springframework.format.support.FormattingConversionServiceFactoryBean"></bean>
2525
<import resource="applicationContext.xml"/>
2626

27+
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
28+
<property name="maxUploadSize" value="5242880"/>
29+
</bean>
2730

2831
</beans>

0 commit comments

Comments
 (0)