лабы гречухин 2 курс / web лаба3
.docxМИНОБРНАУКИ РОССИИ
Санкт-Петербургский государственный
электротехнический университет
«ЛЭТИ» им. В.И. Ульянова (Ленина)
отчет
по лабораторной работе 3
по дисциплине «WEB-программирование»
Студентка гр. 3316 |
|
Кирейкова С.А. |
Преподаватель |
|
Гречухин М.Н. |
Санкт-Петербург
2025
ра
Разработка веб-приложения для специалистов сферы услуг (мастеров красоты и ухода).
Веб-приложение, предназначенное для фрилансеров и мастеров, предоставляющих различные услуги.
Сервис позволяет публиковать предложения, находить клиентов и получать заказы.
Цель проекта - упростить взаимодействие между исполнителями и заказчиками, обеспечив удобную платформу для поиска и заключения сделок .Демонстрация работы разработанного web-приложения приведена на следующих скриншотах (рис.1-3).
Рисунок 1
Рисунок 2
Рисунок 3
Исходный текст сервлета:
package lab3;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
/**
* Servlet implementation class BookList
*/
@WebServlet("/BookList")
public class BookList extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public BookList() {
super();
// Конструктор сервлета
}
/**
* Обрабатывает запросы как GET, так и POST
*
* @param request объект HttpServletRequest
* @param response объект HttpServletResponse
* @throws ServletException если возникает ошибка сервлета
* @throws IOException если возникает ошибка ввода-вывода
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Задаем кодировку для параметров запроса
request.setCharacterEncoding("UTF-8");
// Чтение параметра name из запроса
String name = request.getParameter("name");
String qualification = request.getParameter("qualification");
String contacts = request.getParameter("contacts");
// Задаем тип содержимого для ответа (включая кодировку)
response.setContentType("text/html;charset=UTF-8");
// Получение потока вывода
PrintWriter out = response.getWriter();
try {
// Создание HTML-страницы
//таблица мастеров
out.println("<html>");
out.println("<head><title>Beauty-мастера</title></head>");
out.println("<body style= \"background-color: #bc8f8f; <table border='1'\" >");
out.println("<h1 style='text-align:center;font-family: \"Algerian\";'>Мастера Beauty индустрии </h1>");
out.println("<table border='1' style='text-align:center;border:2px solid #000000;margin: 0 auto;width:80%;font-size:25px;border-radius: 15px;background-color:#FFCCCC; color:#800000;'>");
out.println("<tr><td><b>Имя мастера</b></td><td><b>Квалификация</b></td><td><b>Запись на 31 декабря</b></td><td><b>Контакты</b></td></tr>");
out.println("<tr><td>Татьяна</td><td>Дерматолог</td><td>Занято</td><td><b>89675667867</b></td></tr>");
out.println("<tr><td>Алиса</td><td>Косметолог</td><td>Свободно</td><td><b>89786778899</b></td></tr>");
//динамически добавленный мастер
if (name != null && !name.isEmpty() && qualification!= null && !qualification.isEmpty() && contacts!= null && !contacts.isEmpty()) {
out.println("<tr><td>" + name + "</td><td>"+ qualification +"</td><td>Свободно</td><td>"+contacts+"</td></tr>");
}
out.println("</table>");
out.println("</body>");
out.println("</html>");
//инструкция для мастеров
out.println("<p style='text-align:center; font-size:18px;'>Если вы мастер и у вас есть окошко на 31 декабря, обязательно оставьте вашу заявку. Клиенты сами вас найдут!</p>");
//форма для мастеров
out.println("<form method='GET' action='BookList' style='text-align:center; margin-bottom:20px;'>");
out.println("Имя мастера: <input type='text' name='name'/>");
out.println("Квалификация: <input type='text' name='qualification'/>");
out.println("Контакты: <input type='text' name='contacts'/>");
out.println("<input type='submit' value='Оставить заявку'/>");
out.println("</form>");
} finally {
// Закрытие потока вывода
out.close();
}
}
/**
* Handles the HTTP GET method.
*
* @param request объект HttpServletRequest
* @param response объект HttpServletResponse
* @throws ServletException если возникает ошибка сервлета
* @throws IOException если возникает ошибка ввода-вывода
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP POST method.
*
* @param request объект HttpServletRequest
* @param response объект HttpServletResponse
* @throws ServletException если возникает ошибка сервлета
* @throws IOException если возникает ошибка ввода-вывода
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
}
Распечатка файла web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
version="4.0"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:javaee="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
<display-name>Archetype Created Web Application</display-name>
</web-app>
Файл pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>NIC</groupId>
<artifactId>webapp2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>webapp2 Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>
<build>
<finalName>webapp2</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>javadoc</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Текст документации сервлета, сгенерированный Javadoc:
Class BookList
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
lab3.BookList
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
@WebServlet("/BookList") public class BookList extends javax.servlet.http.HttpServlet
Servlet implementation class BookList
See Also:
Serialized Form
Constructor Summary
Constructors
Constructor
Description
BookList()
Method Summary
All MethodsInstance MethodsConcrete Methods
Modifier and Type
Method
Description
protected void
doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Handles the HTTP GET method.
protected void
doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Handles the HTTP POST method.
protected void
processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Обрабатывает запросы как GET, так и POST
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Details
BookList
public BookList()
See Also:
HttpServlet()
Method Details
processRequest
protected void processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
Обрабатывает запросы как GET, так и POST
Parameters:
request - объект HttpServletRequest
response - объект HttpServletResponse
Throws:
javax.servlet.ServletException - если возникает ошибка сервлета
IOException - если возникает ошибка ввода-вывода
doGet
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
Handles the HTTP GET method.
Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
request - объект HttpServletRequest
response - объект HttpServletResponse
Throws:
javax.servlet.ServletException - если возникает ошибка сервлета
IOException - если возникает ошибка ввода-вывода
doPost
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
Handles the HTTP POST method.
Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
request - объект HttpServletRequest
response - объект HttpServletResponse
Throws:
javax.servlet.ServletException - если возникает ошибка сервлета
IOException - если возникает ошибка ввода-вывода
