Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GridAction extends ActionSupport {
- /**
- *
- */
- private static final long serialVersionUID = -4964110302586165626L;
- private List<Grid> listGrid;
- Grid grid = new Grid();
- private File fileUpload;
- private String fileUploadContentType;
- private String fileUploadFileName;
- private String ImgURL;
- public String saveGrid() {
- try {
- String resultUpload = saveImage();
- if (resultUpload.equalsIgnoreCase("success")) {
- String address = Inet4Address.getLocalHost().getHostAddress();
- ImgURL = "http://" + address + ":8080/PngAppWebApp/temp/"
- + fileUploadFileName;
- grid.setImageUrl(ImgURL);
- new GridDao().saveGrid(grid);
- return SUCCESS;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return ERROR;
- }
- public String editGrid() {
- try {
- String resultUpload = saveImage();
- if (resultUpload.equalsIgnoreCase("success")) {
- String address = Inet4Address.getLocalHost().getHostAddress();
- ImgURL = "http://" + address + ":8080/PngAppWebApp/temp/"
- + fileUploadFileName;
- grid.setImageUrl(getImgURL());
- new GridDao().editGrid(grid);
- return SUCCESS;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return ERROR;
- }
- public String saveImage() throws IOException {
- try {
- ServletContext servletContext = ServletActionContext
- .getServletContext();
- String path = servletContext.getRealPath("/temp");
- System.out.println("Server path:" + path);
- String filePath = servletContext.getRealPath(path);
- System.out.println("path:" + filePath);
- File uploadDir = new File(filePath, fileUploadFileName);
- // if the folder does not exits, creating it
- if (uploadDir.exists() == false) {
- uploadDir.mkdirs();
- }
- File destFile = new File(path, fileUploadFileName);
- FileUtils.copyFile(fileUpload, destFile);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- return ERROR;
- }
- return SUCCESS;
- }
- public String listGrid() {
- try {
- listGrid = new GridDao().listGrid();
- System.out.println("you are in ListUser");
- return SUCCESS;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return ERROR;
- }
- public String preprEditGrid() {
- try {
- grid = new GridDao().preprEditGrid(grid);
- System.out.println("you are in editUser" + grid);
- return SUCCESS;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return ERROR;
- }
- public String deleteGrid() {
- try {
- new GridDao().deleteGrid(grid);
- return SUCCESS;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return ERROR;
- }
- public List<Grid> getListGrid() {
- return listGrid;
- }
- public void setListGrid(List<Grid> listGrid) {
- this.listGrid = listGrid;
- }
- public Grid getGrid() {
- return grid;
- }
- public void setGrid(Grid grid) {
- this.grid = grid;
- }
- public File getFileUpload() {
- return fileUpload;
- }
- public void setFileUpload(File fileUpload) {
- this.fileUpload = fileUpload;
- }
- public String getFileUploadContentType() {
- return fileUploadContentType;
- }
- public void setFileUploadContentType(String fileUploadContentType) {
- this.fileUploadContentType = fileUploadContentType;
- }
- public String getFileUploadFileName() {
- return fileUploadFileName;
- }
- public void setFileUploadFileName(String fileUploadFileName) {
- this.fileUploadFileName = fileUploadFileName;
- }
- public String getImgURL() {
- return ImgURL;
- }
- public void setImgURL(String imgURL) {
- ImgURL = imgURL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement