Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. public class GridAction extends ActionSupport {
  2. /**
  3. *
  4. */
  5. private static final long serialVersionUID = -4964110302586165626L;
  6. private List<Grid> listGrid;
  7. Grid grid = new Grid();
  8.  
  9. private File fileUpload;
  10.  
  11. private String fileUploadContentType;
  12.  
  13. private String fileUploadFileName;
  14.  
  15. private String ImgURL;
  16.  
  17. public String saveGrid() {
  18. try {
  19. String resultUpload = saveImage();
  20. if (resultUpload.equalsIgnoreCase("success")) {
  21.  
  22. String address = Inet4Address.getLocalHost().getHostAddress();
  23. ImgURL = "http://" + address + ":8080/PngAppWebApp/temp/"
  24. + fileUploadFileName;
  25.  
  26. grid.setImageUrl(ImgURL);
  27.  
  28. new GridDao().saveGrid(grid);
  29.  
  30. return SUCCESS;
  31. }
  32. } catch (Exception e) {
  33. e.printStackTrace();
  34. }
  35. return ERROR;
  36.  
  37. }
  38.  
  39. public String editGrid() {
  40. try {
  41. String resultUpload = saveImage();
  42. if (resultUpload.equalsIgnoreCase("success")) {
  43.  
  44. String address = Inet4Address.getLocalHost().getHostAddress();
  45.  
  46. ImgURL = "http://" + address + ":8080/PngAppWebApp/temp/"
  47. + fileUploadFileName;
  48.  
  49. grid.setImageUrl(getImgURL());
  50.  
  51. new GridDao().editGrid(grid);
  52. return SUCCESS;
  53. }
  54. } catch (Exception e) {
  55. e.printStackTrace();
  56. }
  57. return ERROR;
  58. }
  59.  
  60. public String saveImage() throws IOException {
  61.  
  62. try {
  63.  
  64. ServletContext servletContext = ServletActionContext
  65. .getServletContext();
  66. String path = servletContext.getRealPath("/temp");
  67. System.out.println("Server path:" + path);
  68. String filePath = servletContext.getRealPath(path);
  69. System.out.println("path:" + filePath);
  70. File uploadDir = new File(filePath, fileUploadFileName);
  71. // if the folder does not exits, creating it
  72. if (uploadDir.exists() == false) {
  73. uploadDir.mkdirs();
  74. }
  75. File destFile = new File(path, fileUploadFileName);
  76. FileUtils.copyFile(fileUpload, destFile);
  77.  
  78. } catch (FileNotFoundException e) {
  79. e.printStackTrace();
  80. return ERROR;
  81. }
  82. return SUCCESS;
  83. }
  84.  
  85. public String listGrid() {
  86. try {
  87. listGrid = new GridDao().listGrid();
  88. System.out.println("you are in ListUser");
  89. return SUCCESS;
  90. } catch (Exception e) {
  91. e.printStackTrace();
  92. }
  93. return ERROR;
  94. }
  95.  
  96. public String preprEditGrid() {
  97. try {
  98.  
  99. grid = new GridDao().preprEditGrid(grid);
  100. System.out.println("you are in editUser" + grid);
  101. return SUCCESS;
  102. } catch (Exception e) {
  103. e.printStackTrace();
  104. }
  105. return ERROR;
  106. }
  107.  
  108. public String deleteGrid() {
  109. try {
  110. new GridDao().deleteGrid(grid);
  111. return SUCCESS;
  112.  
  113. } catch (Exception e) {
  114. e.printStackTrace();
  115. }
  116. return ERROR;
  117.  
  118. }
  119.  
  120. public List<Grid> getListGrid() {
  121. return listGrid;
  122. }
  123.  
  124. public void setListGrid(List<Grid> listGrid) {
  125. this.listGrid = listGrid;
  126. }
  127.  
  128. public Grid getGrid() {
  129. return grid;
  130. }
  131.  
  132. public void setGrid(Grid grid) {
  133. this.grid = grid;
  134. }
  135.  
  136. public File getFileUpload() {
  137. return fileUpload;
  138. }
  139.  
  140. public void setFileUpload(File fileUpload) {
  141. this.fileUpload = fileUpload;
  142. }
  143.  
  144. public String getFileUploadContentType() {
  145. return fileUploadContentType;
  146. }
  147.  
  148. public void setFileUploadContentType(String fileUploadContentType) {
  149. this.fileUploadContentType = fileUploadContentType;
  150. }
  151.  
  152. public String getFileUploadFileName() {
  153. return fileUploadFileName;
  154. }
  155.  
  156. public void setFileUploadFileName(String fileUploadFileName) {
  157. this.fileUploadFileName = fileUploadFileName;
  158. }
  159.  
  160. public String getImgURL() {
  161. return ImgURL;
  162. }
  163.  
  164. public void setImgURL(String imgURL) {
  165. ImgURL = imgURL;
  166. }
  167.  
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement