From 8f42d4a320b9ec3d8f7002269e0c2b36397dbd21 Mon Sep 17 00:00:00 2001 From: roma-dxunvrs Date: Mon, 2 Nov 2026 17:27:14 +0300 Subject: [PATCH] web add some tasks for 1 milestone --- Итмо/Лабы/Веб/Рубежка 1.md | 154 ++++++++++++++++++++++++++++++++++++- 1 file changed, 153 insertions(+), 1 deletion(-) diff --git a/Итмо/Лабы/Веб/Рубежка 1.md b/Итмо/Лабы/Веб/Рубежка 1.md index 94a5dd8..08eab10 100644 --- a/Итмо/Лабы/Веб/Рубежка 1.md +++ b/Итмо/Лабы/Веб/Рубежка 1.md @@ -8,4 +8,156 @@ - [Еще](https://github.com/AppLoidx/Web-Development-Cheats/blob/master/itmo-university/module%20tests/ModuleTest1Questions.md) 2022 год - [Задания](https://github.com/AppLoidx/Web-Development-Cheats/blob/master/itmo-university/module%20tests/ModuleTest1.md) на код 2022 года - Прошлогодняя [рубежка](https://github.com/sub-myitmo/web-rubezhka1) -- [Еще](https://invited-digit-866.notion.site/2022-53c853d396364002b29a1331dfc78bba#80cee9d88a03495ea134ec05a365d43c) заметки в notion от 2022 годар \ No newline at end of file +- [Еще](https://invited-digit-866.notion.site/2022-53c853d396364002b29a1331dfc78bba#80cee9d88a03495ea134ec05a365d43c) заметки в notion от 2022 года +## Разбор типовых задач +### 1. Сделать слошную синюю границу 2px у текстового ввода внутри класса `auth_form` при фокусе +```CSS +.auth-form input[type="text"]:focus { + border: 2px solid blue; +} +``` +### 2. Написать миксин на SCSS и использовать его в классе `user-card`, добавить вложенный стиль при наведении курсора +```SCSS +@mixin card-style($bg-color: #ffffff) { + background-color: $bg-color; + border-radius: 8px; +} + +.user-card { + @include card-style; + &:hover { + opacity: 0.8; + } +} +``` +### 3. Написать код на JS, который читает поле ввода, если там число, то выводит удвоенное значение в консоль, иначе сообщение об ошибке в alert +```JavaScript +const form = document.querySelector("#calcForm"); +const input = document.querySelector("#numInput"); +form.addEventListener("submit", (event) => { + event.preventDefault(); + const text = input.value; + const number = parseFloat(text); + if (isNan(number)) { + alert("Введите число"); + } else { + console.log(number*2); + } +}); +``` +### 4. Написать асинхронную функцию, которая делает POST запрос с координатами точки и возвращает json-ответ +```JavaScript +async function sendCoordinates(x, y) { + const url = "/api/points"; + const data = {x: x, y: y}; + const response = await fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify(data) + }); + + if (!response.ok) { + throw new Error(); + } + const res = await response.json(); + return res; +} +``` +### 5. Через JQuery поменять элемент с классом `content-box` и вывести значение из поля ввода с id `statusInput` +```JavaScript +$("#toggle-btn").on("click", () => { + $(".content-box").slideUp().css("color", "red"); + console.log($("#statusInput").val()); +}); +``` +### 6. Написать FCGI-сценарий, который проверяет строку запроса, если там есть слово `ping`, то выводит `pong`. Иначе возвращает 400 ошибку +```Java +public class Main { + public static void main(String[] args) { + FCGIInterface fcgi = new FCGIInterface(); + + while (fcgi.accept() >= 0) { + if (FCGIInterface.request == null) { + continue; + } + + String query = FCGIInterface.request.getProperty("QUERY_STRING"); + if (query != null && query.contains("ping")) { + System.out.println("Content-Type: text/plain\n"); + System.out.println("ping"); + } else { + System.out.println("Status: 400 Bad Request"); + System.out.println("Content-Type: text/plain\n"); + System.out.println("Bad Request"); + } + } + } +} +``` +### 7. Написать сервлет, который считает количество заходов пользователя на сайт через HTTP-сессии +```Java +@WebServlet("/counter") +public class MyServlet extends HttpServlet { + @Override + public void doGet(HttpServletRequest req, HttpServletResponse res) { + HttpSession session = req.getSession(); + if (session.getAttribute("visitCount") == null) { + session.setAttribute("visitCount", 0); + } + int count = (Integer) session.getAttribute("visitCount") + 1; + session.setAttribute("visitCount", count); + res.setContentType("text/plain"); + PrintWriter out = res.getWriter(); + out.println("Вы посетили страницу %d раз".format(count)); + } +} +``` +### 8. Написать сервлет, который проверяет роль пользователя и пропускает, если он админ, иначе переадресация на сообщение об ошибке +```Java +@WebServlet("/task") +public class MyServlet extends HttpServlet { + @Override + public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { + String role = req.getParameter("role"); + if (role == null || !role.equals("admin")) { + res.sendRedirect("/access-denied.html"); + } + req.setAttribute("secretData", "TopSecret123"); + RequestDispatcher disp = res.getRequestDispatcher("/admin.jsp"); + disp.forward(req, res); + } +} +``` +### 9. Написать фильтр, который пропускает пользователя дальше, только если в его сессии есть атрибут `user` +```Java +@WebFilter("/secure/*") +public class MyFilter implements Filter { + @Override + public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws ServletException, IOException { + HttpServletRequest httpReq = (HttpServletRequest) req; + HttpServletResponse httpRes = (HttpServletResponse) res; + HttpSession session = httpReq.getSession(); + if (session.getAttribute("user")==null) { + httpRes.setContentType("text/plain"); + httpRes.setStatus(403); + hhtpRes.getWriter().println("Вход воспрещен"); + } else { + chain.doFilter(req, res); + } + } +} +``` +### 10. Реализовать функцию на JavaScript, которая будет закрывать текущее окно, если в нем открыт гугл +```JavaScript +function closeWindow() { + if (window.location.href === "https://www.google.ru") { + window.close(); + } +} +``` +### 11. Открытие в новом окне браузера гугла через JS +```JavaScript +window.open("http://google.com", "newwin", "width=1200,height=600"); +```