esoe 1 year ago
parent
commit
3d7f68f1bb
  1. 3
      .vscode/settings.json
  2. 36
      src/main/java/ru/molokoin/home/entities/Media.java
  3. 55
      src/main/java/ru/molokoin/home/servlets/Main.java
  4. 155
      src/main/java/ru/molokoin/home/servlets/Storage.java
  5. 9
      src/main/resources/META-INF/persistance.xml
  6. 11
      src/main/sql-scripts/home.sql
  7. 6
      src/main/webapp/WEB-INF/web.xml
  8. 1
      src/main/webapp/content/test.txt
  9. 3
      src/main/webapp/index.html
  10. 9
      target/classes/META-INF/persistance.xml
  11. BIN
      target/classes/ru/molokoin/home/entities/Media.class
  12. BIN
      target/classes/ru/molokoin/home/servlets/Main.class
  13. BIN
      target/classes/ru/molokoin/home/servlets/Storage.class
  14. BIN
      target/home.war
  15. 9
      target/home/WEB-INF/classes/META-INF/persistance.xml
  16. BIN
      target/home/WEB-INF/classes/ru/molokoin/home/entities/Media.class
  17. BIN
      target/home/WEB-INF/classes/ru/molokoin/home/servlets/Main.class
  18. BIN
      target/home/WEB-INF/classes/ru/molokoin/home/servlets/Storage.class
  19. 6
      target/home/WEB-INF/web.xml
  20. 1
      target/home/content/test.txt
  21. 3
      target/home/index.html
  22. 2
      target/maven-archiver/pom.properties
  23. 3
      target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
  24. 3
      target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

3
.vscode/settings.json vendored

@ -1,3 +0,0 @@ @@ -1,3 +0,0 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}

36
src/main/java/ru/molokoin/home/entities/Media.java

@ -0,0 +1,36 @@ @@ -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)
}

55
src/main/java/ru/molokoin/home/servlets/Main.java

@ -0,0 +1,55 @@ @@ -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>");
}
}

155
src/main/java/ru/molokoin/home/servlets/Storage.java

@ -0,0 +1,155 @@ @@ -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>");
}
}

9
src/main/resources/META-INF/persistance.xml

@ -0,0 +1,9 @@ @@ -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>

11
src/main/sql-scripts/home.sql

@ -0,0 +1,11 @@ @@ -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;

6
src/main/webapp/WEB-INF/web.xml

@ -5,3 +5,9 @@ @@ -5,3 +5,9 @@
<web-app>
<display-name>molokoin.ru</display-name>
</web-app>
<!-- <multipart-config>
<location>/tmp</location>
<max-request-size>418018841</max-request-size>
<max-file-size>20848820</max-file-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config> -->

1
src/main/webapp/content/test.txt

@ -0,0 +1 @@ @@ -0,0 +1 @@
test1

3
src/main/webapp/index.html

@ -14,6 +14,9 @@ @@ -14,6 +14,9 @@
</header>
<aside>
<a href="hello">hello</a>
<a href="media">media</a>
<a href="main">main</a>
<a href="storage">storage</a>
</aside>
<main>
<p >some info</p>

9
target/classes/META-INF/persistance.xml

@ -0,0 +1,9 @@ @@ -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>

BIN
target/classes/ru/molokoin/home/entities/Media.class

Binary file not shown.

BIN
target/classes/ru/molokoin/home/servlets/Main.class

Binary file not shown.

BIN
target/classes/ru/molokoin/home/servlets/Storage.class

Binary file not shown.

BIN
target/home.war

Binary file not shown.

9
target/home/WEB-INF/classes/META-INF/persistance.xml

@ -0,0 +1,9 @@ @@ -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>

BIN
target/home/WEB-INF/classes/ru/molokoin/home/entities/Media.class

Binary file not shown.

BIN
target/home/WEB-INF/classes/ru/molokoin/home/servlets/Main.class

Binary file not shown.

BIN
target/home/WEB-INF/classes/ru/molokoin/home/servlets/Storage.class

Binary file not shown.

6
target/home/WEB-INF/web.xml

@ -5,3 +5,9 @@ @@ -5,3 +5,9 @@
<web-app>
<display-name>molokoin.ru</display-name>
</web-app>
<!-- <multipart-config>
<location>/tmp</location>
<max-request-size>418018841</max-request-size>
<max-file-size>20848820</max-file-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config> -->

1
target/home/content/test.txt

@ -0,0 +1 @@ @@ -0,0 +1 @@
test1

3
target/home/index.html

@ -14,6 +14,9 @@ @@ -14,6 +14,9 @@
</header>
<aside>
<a href="hello">hello</a>
<a href="media">media</a>
<a href="main">main</a>
<a href="storage">storage</a>
</aside>
<main>
<p >some info</p>

2
target/maven-archiver/pom.properties

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
#Created by Apache Maven 3.8.5
artifactId=home
groupId=ru.molokoin
artifactId=home
version=1.0

3
target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
ru\molokoin\home\servlets\Storage.class
ru\molokoin\home\entities\Media.class
ru\molokoin\home\servlets\Main.class

3
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

@ -0,0 +1,3 @@ @@ -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…
Cancel
Save