esoe
1 year ago
24 changed files with 311 additions and 4 deletions
@ -1,3 +0,0 @@ |
|||||||
{ |
|
||||||
"java.configuration.updateBuildConfiguration": "interactive" |
|
||||||
} |
|
@ -0,0 +1,36 @@ |
|||||||
|
package ru.molokoin.home.entities; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
import jakarta.persistence.Basic; |
||||||
|
import jakarta.persistence.Column; |
||||||
|
import jakarta.persistence.Entity; |
||||||
|
import jakarta.persistence.GeneratedValue; |
||||||
|
import jakarta.persistence.GenerationType; |
||||||
|
import jakarta.persistence.Id; |
||||||
|
import jakarta.persistence.Lob; |
||||||
|
import jakarta.persistence.NamedQueries; |
||||||
|
import jakarta.persistence.NamedQuery; |
||||||
|
import jakarta.persistence.Table; |
||||||
|
/** |
||||||
|
* Класс сущности, |
||||||
|
* хранит сведения о файлах размещенных на сервере |
||||||
|
* и ссылку на размещенный файл |
||||||
|
*/ |
||||||
|
@Entity |
||||||
|
@Table(name = "Medias") |
||||||
|
@NamedQueries({ |
||||||
|
@NamedQuery(name = "Medias.findAll", |
||||||
|
query = "SELECT m FROM Media m") |
||||||
|
}) |
||||||
|
public class Media implements Serializable{ |
||||||
|
@Id //уникальный идентификатор ресурса
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY) |
||||||
|
@Basic(optional = false) //не может быть null
|
||||||
|
@Column(name = "id") |
||||||
|
private Integer id;// PRIMARY KEY AUTO_INCREMENT
|
||||||
|
private String name;// name varchar(300)
|
||||||
|
private String type;// varchar(10)
|
||||||
|
private String description;// varchar(1000)
|
||||||
|
private Integer parent;// DEFAULT (0)
|
||||||
|
} |
@ -0,0 +1,55 @@ |
|||||||
|
package ru.molokoin.home.servlets; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.io.PrintWriter; |
||||||
|
|
||||||
|
import jakarta.servlet.ServletException; |
||||||
|
import jakarta.servlet.annotation.WebServlet; |
||||||
|
import jakarta.servlet.http.HttpServlet; |
||||||
|
import jakarta.servlet.http.HttpServletRequest; |
||||||
|
import jakarta.servlet.http.HttpServletResponse; |
||||||
|
|
||||||
|
@WebServlet(name = "Main", value = "/main") |
||||||
|
public class Main extends HttpServlet{ |
||||||
|
@Override |
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { |
||||||
|
page(request, response); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { |
||||||
|
page(request, response); |
||||||
|
} |
||||||
|
|
||||||
|
private void page(HttpServletRequest request, HttpServletResponse response) throws IOException { |
||||||
|
request.setCharacterEncoding("UTF-8"); |
||||||
|
response.setContentType("text/html; charset=UTF-8"); |
||||||
|
|
||||||
|
PrintWriter out = response.getWriter(); |
||||||
|
out.println("<!DOCTYPE html>"); |
||||||
|
out.println("<html lang=\"en\">"); |
||||||
|
out.println("<head>"); |
||||||
|
out.println(" <meta charset=\"UTF-8\">"); |
||||||
|
out.println(" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">"); |
||||||
|
out.println(" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"); |
||||||
|
out.println(" <title>home:main</title>"); |
||||||
|
/** |
||||||
|
* Подключение стилей |
||||||
|
*/ |
||||||
|
out.println(" <link href=\"layout/styles.css\" rel=\"stylesheet\">"); |
||||||
|
out.println("</head>"); |
||||||
|
out.println("<html><body >"); |
||||||
|
out.println("<header>"); |
||||||
|
out.println(" <h1 >molokoin.ru : main</h1>"); |
||||||
|
out.println("</header>"); |
||||||
|
out.println("<aside>"); |
||||||
|
out.println("</aside>"); |
||||||
|
out.println("<main>"); |
||||||
|
out.println("</main>"); |
||||||
|
out.println("<footer>"); |
||||||
|
out.println("</footer>"); |
||||||
|
out.println("</body></html>"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,155 @@ |
|||||||
|
package ru.molokoin.home.servlets; |
||||||
|
|
||||||
|
import java.io.BufferedReader; |
||||||
|
import java.io.File; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.io.InputStreamReader; |
||||||
|
import java.io.PrintWriter; |
||||||
|
import java.io.Reader; |
||||||
|
import java.nio.charset.StandardCharsets; |
||||||
|
import java.nio.file.Paths; |
||||||
|
|
||||||
|
import jakarta.servlet.ServletException; |
||||||
|
import jakarta.servlet.annotation.MultipartConfig; |
||||||
|
import jakarta.servlet.annotation.WebServlet; |
||||||
|
import jakarta.servlet.http.HttpServlet; |
||||||
|
import jakarta.servlet.http.HttpServletRequest; |
||||||
|
import jakarta.servlet.http.HttpServletResponse; |
||||||
|
import jakarta.servlet.http.Part; |
||||||
|
/** |
||||||
|
* Сервлет файлообменника |
||||||
|
*/ |
||||||
|
@MultipartConfig(fileSizeThreshold = 2024 * 2024, |
||||||
|
maxFileSize = 2024 * 2024 * 5, |
||||||
|
maxRequestSize = 2024 * 2024 * 5 * 5) |
||||||
|
@WebServlet(name = "Storage", value = "/storage") |
||||||
|
public class Storage extends HttpServlet{ |
||||||
|
/** |
||||||
|
* Возвращает пользователю страницу, содержащую: |
||||||
|
* - перечень доступных для скачивания файлов |
||||||
|
* - форму для загрузки файла на сервер |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { |
||||||
|
//page(request, response);
|
||||||
|
request.setCharacterEncoding("UTF-8"); |
||||||
|
response.setContentType("text/html; charset=UTF-8"); |
||||||
|
|
||||||
|
PrintWriter out = response.getWriter(); |
||||||
|
out.println("<!DOCTYPE html>"); |
||||||
|
out.println("<html lang=\"en\">"); |
||||||
|
out.println("<head>"); |
||||||
|
out.println(" <meta charset=\"UTF-8\">"); |
||||||
|
out.println(" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">"); |
||||||
|
out.println(" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"); |
||||||
|
out.println(" <title>home:storage</title>"); |
||||||
|
// Подключение стилей
|
||||||
|
out.println(" <link href=\"layout/styles.css\" rel=\"stylesheet\">"); |
||||||
|
out.println("</head>"); |
||||||
|
out.println("<html><body >"); |
||||||
|
out.println("<header>"); |
||||||
|
out.println(" <h1 >molokoin.ru : storage</h1>"); |
||||||
|
out.println("</header>"); |
||||||
|
out.println("<aside>"); |
||||||
|
out.println(" <p>controls</p>"); |
||||||
|
//форма upload
|
||||||
|
out.println("<form action=\"storage\" method=\"post\" enctype=\"multipart/form-data\">"); |
||||||
|
out.println(" <input type=\"text\" name=\"description\" />"); |
||||||
|
out.println(" <input type=\"file\" name=\"file\" />"); |
||||||
|
out.println(" <input type=\"submit\" />"); |
||||||
|
out.println("</form>"); |
||||||
|
out.println("</aside>"); |
||||||
|
out.println("<main>"); |
||||||
|
out.println(" <p>tables of content</p>"); |
||||||
|
out.println("</main>"); |
||||||
|
out.println("<footer>"); |
||||||
|
out.println("</footer>"); |
||||||
|
out.println("</body></html>"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { |
||||||
|
page(request, response); |
||||||
|
} |
||||||
|
|
||||||
|
private void page(HttpServletRequest request, HttpServletResponse response) throws IOException { |
||||||
|
request.setCharacterEncoding("UTF-8"); |
||||||
|
response.setContentType("text/html; charset=UTF-8"); |
||||||
|
|
||||||
|
PrintWriter out = response.getWriter(); |
||||||
|
out.println("<!DOCTYPE html>"); |
||||||
|
out.println("<html lang=\"en\">"); |
||||||
|
out.println("<head>"); |
||||||
|
out.println(" <meta charset=\"UTF-8\">"); |
||||||
|
out.println(" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">"); |
||||||
|
out.println(" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"); |
||||||
|
out.println(" <title>home:storage</title>"); |
||||||
|
// Подключение стилей
|
||||||
|
out.println(" <link href=\"layout/styles.css\" rel=\"stylesheet\">"); |
||||||
|
out.println("</head>"); |
||||||
|
out.println("<html><body >"); |
||||||
|
out.println("<header>"); |
||||||
|
out.println(" <h1 >molokoin.ru : storage</h1>"); |
||||||
|
out.println("</header>"); |
||||||
|
out.println("<aside>"); |
||||||
|
out.println(" <p>controls</p>"); |
||||||
|
out.println("</aside>"); |
||||||
|
out.println("<main>"); |
||||||
|
out.println(" <p>tables of content</p>"); |
||||||
|
// обработка данных
|
||||||
|
String description = request.getParameter("description"); // Retrieves <input type="text" name="description">
|
||||||
|
out.println(" <p>"+description+"</p>"); |
||||||
|
|
||||||
|
String uploadPath = "/srv/apps/home/exchange"; |
||||||
|
File uploadDir = new File(uploadPath); |
||||||
|
if (!uploadDir.exists()) { |
||||||
|
out.println(" <p>"+"Директория для записи файла: " + uploadPath + " не доступна!!!" + "</p>"); |
||||||
|
} else { |
||||||
|
try { |
||||||
|
Part filePart = request.getPart("file"); |
||||||
|
String fileName = Paths.get(filePart.getSubmittedFileName()).getFileName().toString(); |
||||||
|
out.println(" <p>"+fileName+"</p>"); |
||||||
|
for (Part part : request.getParts()) { |
||||||
|
part.write(uploadPath + File.separator + fileName); |
||||||
|
//out.println(" <p>"+fileName + "содержит: " + part.getSize()+"</p>");
|
||||||
|
} |
||||||
|
} catch (ServletException e) { |
||||||
|
//e.printStackTrace();
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Part filePart;
|
||||||
|
// try {
|
||||||
|
// filePart = request.getPart("file");// Retrieves <input type="file" name="file">
|
||||||
|
// String fileName = Paths.get(filePart.getSubmittedFileName()).getFileName().toString(); // MSIE fix.
|
||||||
|
// out.println(" <p>" + fileName + " contains: " + "</p>");
|
||||||
|
// InputStream fileContent = filePart.getInputStream();
|
||||||
|
// //читаем из файла
|
||||||
|
// StringBuilder textBuilder = new StringBuilder();
|
||||||
|
// try (Reader reader = new BufferedReader(new InputStreamReader
|
||||||
|
// (fileContent, StandardCharsets.UTF_8))) {
|
||||||
|
// int c = 0;
|
||||||
|
// while ((c = reader.read()) != -1) {
|
||||||
|
// textBuilder.append((char) c);
|
||||||
|
// }
|
||||||
|
// out.println(" <p>" + fileName + " contains: " + textBuilder.toString() + "</p>");
|
||||||
|
// }
|
||||||
|
// } catch (ServletException e) {
|
||||||
|
// // TODO Auto-generated catch block
|
||||||
|
// //e.printStackTrace();
|
||||||
|
// out.println(" <p>" + "Файл вызвал ошибку: " + "</p>");
|
||||||
|
// }
|
||||||
|
out.println("</main>"); |
||||||
|
out.println("<footer>"); |
||||||
|
out.println("</footer>"); |
||||||
|
out.println("</body></html>"); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
@ -0,0 +1,9 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<persistence xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemalocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"> |
||||||
|
<persistence-unit name="Repository" transaction-type="JTA"> |
||||||
|
<description>Подключение к базе molokoin.ru:3306/home</description> |
||||||
|
<jta-data-source>java:/home</jta-data-source> |
||||||
|
<!-- <class>ru.molokoin.home.entities.Media</class> --> |
||||||
|
<exclude-unlisted-classes>true</exclude-unlisted-classes> |
||||||
|
</persistence-unit> |
||||||
|
</persistence> |
@ -0,0 +1,11 @@ |
|||||||
|
create database home; |
||||||
|
|
||||||
|
create table home.repository ( |
||||||
|
id INT PRIMARY KEY AUTO_INCREMENT, |
||||||
|
name varchar(300) not null, |
||||||
|
type varchar(10), |
||||||
|
description varchar(1000), |
||||||
|
parent INT DEFAULT(0) |
||||||
|
); |
||||||
|
|
||||||
|
ALTER TABLE home.repository ADD data LARGEBLOB; |
@ -0,0 +1,9 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<persistence xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemalocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"> |
||||||
|
<persistence-unit name="Repository" transaction-type="JTA"> |
||||||
|
<description>Подключение к базе molokoin.ru:3306/home</description> |
||||||
|
<jta-data-source>java:/home</jta-data-source> |
||||||
|
<!-- <class>ru.molokoin.home.entities.Media</class> --> |
||||||
|
<exclude-unlisted-classes>true</exclude-unlisted-classes> |
||||||
|
</persistence-unit> |
||||||
|
</persistence> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,9 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<persistence xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0" xsi:schemalocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"> |
||||||
|
<persistence-unit name="Repository" transaction-type="JTA"> |
||||||
|
<description>Подключение к базе molokoin.ru:3306/home</description> |
||||||
|
<jta-data-source>java:/home</jta-data-source> |
||||||
|
<!-- <class>ru.molokoin.home.entities.Media</class> --> |
||||||
|
<exclude-unlisted-classes>true</exclude-unlisted-classes> |
||||||
|
</persistence-unit> |
||||||
|
</persistence> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +1,4 @@ |
|||||||
#Created by Apache Maven 3.8.5 |
#Created by Apache Maven 3.8.5 |
||||||
artifactId=home |
|
||||||
groupId=ru.molokoin |
groupId=ru.molokoin |
||||||
|
artifactId=home |
||||||
version=1.0 |
version=1.0 |
||||||
|
@ -0,0 +1,3 @@ |
|||||||
|
ru\molokoin\home\servlets\Storage.class |
||||||
|
ru\molokoin\home\entities\Media.class |
||||||
|
ru\molokoin\home\servlets\Main.class |
@ -0,0 +1,3 @@ |
|||||||
|
C:\Users\Strannik\Documents\esoe\code\home\src\main\java\ru\molokoin\home\servlets\Storage.java |
||||||
|
C:\Users\Strannik\Documents\esoe\code\home\src\main\java\ru\molokoin\home\entities\Media.java |
||||||
|
C:\Users\Strannik\Documents\esoe\code\home\src\main\java\ru\molokoin\home\servlets\Main.java |
Loading…
Reference in new issue