Skip to content

Instantly share code, notes, and snippets.

@romcter romcter/Class

Last active Jun 30, 2020
Embed
What would you like to do?
package Package;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class Class extends HttpServlet {
private int q1_1 = 0;
private int q1_2 = 0;
private int q2_1 = 0;
private int q2_2 = 0;
private int q3_1 = 0;
private int q3_2 = 0;
private int q4_1 = 0;
private int q4_2 = 0;
private int q5_1 = 0;
private int q5_2 = 0;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
RequestDispatcher requestDispatcher = req.getServletContext().getRequestDispatcher("/index.jsp");
String name = req.getParameter("name");
String surname = req.getParameter("surname");
String age = req.getParameter("age");
Users person = new Users(name, surname, age);
final String sex = req.getParameter("sex");
final String status = req.getParameter("status");
final String like = req.getParameter("like");
final String computer = req.getParameter("computer");
final String street = req.getParameter("street");
if(sex == null || status == null || like == null || computer == null || street == null) requestDispatcher.forward(req, resp);
if(sex.equals("true") || sex == "true") q1_1++;
if(sex.equals("false") || sex == "false") q1_2++;
if(status.equals("true") || status == "true") q2_1++;
if(status.equals("false") || status == "false") q2_2++;
if(like.equals("true") || like == "true") q3_1++;
if(like.equals("false") || like == "false") q3_2++;
if(computer.equals("true") || computer == "true") q4_1++;
if(computer.equals("false") || computer == "false") q4_2++;
if(street.equals("true") || street == "true") q5_1++;
if(street.equals("false") || street == "false") q5_2++;
req.setAttribute("true1",q1_1);
req.setAttribute("true2",q2_1);
req.setAttribute("true3",q3_1);
req.setAttribute("true4",q4_1);
req.setAttribute("true5",q5_1);
req.setAttribute("false1",q1_2);
req.setAttribute("false2",q2_2);
req.setAttribute("false3",q3_2);
req.setAttribute("false4",q4_2);
req.setAttribute("false5",q5_2);
RequestDispatcher dispatcher = req.getServletContext().getRequestDispatcher("/site.jsp");
dispatcher.forward(req, resp);
}
private class Users {
private final String name;
private final String surname;
private final String age;
public Users(String name, String surname, String age) {
this.name = name;
this.surname = surname;
this.age = age;
}
}
}
<%--
Created by IntelliJ IDEA.
User: macbookpro
Date: 28.06.2020
Time: 17:46
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Index</title>
<link href="/css/css.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="form-style-5">
<form action="/class" method="POST">
<label for="name">User Name:
<input type="text" name="name" id="name" required/><br>
</label>
<label for="surname">Surname:
<input type="text" name="surname" id="surname"required/><br>
</label>
<label for="age">Age:
<input type="number" name="age" id="age" min="10" max="80"required/><br>
</label>
Who are you(Man/Woman)?<br>
<input type="radio" name="sex" value="true"/>Man
<input type="radio" name="sex" value="false"/>Woman<br>
Do you have pair?<br>
<input type="radio" name="status" value="true"/>Married
<input type="radio" name="status" value="false"/>Singe<br>
Do you like JAVA?<br>
<input type="radio" name="like" value="true"/>Yes
<input type="radio" name="like" value="false"/>Noo<br>
What the computer you used?<br>
<input type="radio" name="computer" value="true">Windows
<input type="radio" name="computer" value="false">MAC<br>
Do you often go outside on carantin?<br>
<input type="radio" name="street" value="true">No
<input type="radio" name="street" value="false">Often<br>
<input type="submit" value="GO IN TABLE">
</form>
</div>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: macbookpro
Date: 28.06.2020
Time: 17:51
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="Package.Class" %>
<html>
<head>
<title>Title</title>
<link href="/css/css.css" rel="stylesheet" type="text/css">
</head>
<body>
<% Class klas = new Class();%>
<div class="form-style-5">
<form action="/class" method="POST">
<table border="1" bordercolor="000">
<caption>Количество ответов на вопросы</caption>
<tr>
<th>Вопрос</th>
<th colspan="2">Да ОТВЕТЫ НЕТ</th>
</tr>
<tr>
<td>Who are you(Man/Woman)</td>
<td>${true1}</td>
<td>${false1}</td>
</tr>
<tr>
<td>Do you have pair</td>
<td>${true2}</td>
<td>${false2}</td>
</tr>
<tr>
<td>Do you like JAVA</td>
<td>${true3}</td>
<td>${false3}</td>
</tr>
<tr>
<td>What the computer you used</td>
<td>${true4}</td>
<td>${false4}</td>
</tr>
<tr>
<td>Do you often go outside on carantin</td>
<td>${true5}</td>
<td>${false5}</td>
</tr>
</table>
<a href="index.jsp">Вернуться к голосованию</a><br>
</form>
</div>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
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"
version="4.0">
<servlet>
<servlet-name>Class</servlet-name>
<servlet-class>Package.Class</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Class</servlet-name>
<url-pattern>/class</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Site</servlet-name>
<jsp-file>/web/site.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>Site</servlet-name>
<url-pattern>/site</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Index</servlet-name>
<jsp-file>/web/index.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>Index</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
</web-app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.