The application must copy all files from one directory to another, and the path to the directory from where and where should be done through the Web application. There are two .jsp files:

1. Main page where there are two input fields (from, to).

2. And the second, where the value will return, that all files are copied.

That's what I could roll, then a complete stupor, what to do next ...

СopyFiles.java

import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import org.omg.Security.Public; public class CopyFiles { private String text1; private String text2; public void setText1(String text1) { this.text1 = text1; } public void setText2(String text2) { this.text2 = text2; } public String getText1() { return text1; } public String getText2() { return text2; } public List<String> getList() { return getFiles(new src(text1), new dest(text2)); } public void copy (File src, File dest) throws IOException { if (src.isDirectory()) { if(!dest.exists()) { dest.mkdir(); System.out.println("Папка скопирована из " + src + " в " + dest); } String files[] = src.list(); for (String fileName : files) { File srcFile = new File (src, fileName); File destFile = new File (dest, fileName); copy(srcFile, destFile); } } else { fileCopy(src, dest); } } private void fileCopy(File src, File dest) throws IOException { InputStream in = null; OutputStream out = null; try { in = new FileInputStream(src); out = new FileOutputStream(dest); byte[] buffer = new byte [1024]; int lenght; while ((lenght = in.read(buffer)) > 0) { out.write(buffer, 0, lenght); } } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } System.out.println("Файлы скопированы из: " + src + " в " + dest); } } 

index.jsp

 <!DOCTYPE HTML> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <html> <head> <title>mainpage</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <br> <td> <form action="copypage.jsp" method="POST" > Сopy From : <input type="text" name="text1" > to <input type="text" name="text2" > <td><input type="submit" name="Submit" value="Submit"></td> </form> </td> </body> </html> 

copypage.jsp

 !DOCTYPE HTML><%@page language="java"contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@page import="ru.sbrf.asfs.stub.getCardInfo.CopyFiles"%> <%@page import="java.util.List"%> <% CopyFiles copyfiles = new CopyFiles(); String from = request.getParameter("text1"); String to = request.getParameter("text2"); System.out.print(from); System.out.print(to); copyfiles.setText1(from); copyfiles.setText1(to); %> <html> <head> <title>Copypage</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> </body> </html> 

    1 answer 1

    Perhaps you need to make a web application and run it on one of the http servers. For example , you can make a servlet and run it on a tomcat servlet container, and call it from a jsp page.