JSFiddle - React, Tailwind, and code Playground

by Vlady_32

HTML

View.jsp

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<head>
		<title>View page</title>
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/jsp/css/viewStyle.css" media="all">
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/jsp/css/mainStyle.css" media="all">
		<script type="text/javascript" src="${pageContext.request.contextPath}/jsp/js/jquery-2.2.2.min.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/jsp/js/main.js"></script>
	</head>
	<body>
		<p class="error">${errorView}</p>
		<table class="${errorView.trim() eq 'Downloading data error' ? 'hide' : 'showTable'}">
		<caption>Телефонный справочник</caption>
			<tr>
				<th>№ п/п</th>
				<th>Ф.И.О.</th>
				<th>Адрес</th>
				<th>Номер телефона</th>
			</tr>
			<c:forEach var="el" items="${listRecords}" varStatus="status">
				<tr>
					<td class="links items" data-item="${el.item}"><c:out value="${status.count + currentPosition}"/></td>
					<td><c:out value="${el.fullName}"/></td>
					<td><c:out value="${el.address}"/></td>
					<td><c:out value="${el.phoneNumber}"/></td>
				</tr>
			</c:forEach>
		</table>
		<div id="navPages">
			<c:forEach var="pages" begin="1" end="${qualityPages}">
				<a class="pages">${pages}</a>
			</c:forEach>
		</div>
	</body>
</html>

CSS

Класс viewCommand - получение страницы овтета с контентом
/**
 * This class implements inerface IActionCommand and realizes method execute.
 */
public class ViewCommand implements IActionCommand {

    @Override
    public String execute(final SessionRequest request) {
        String page = null;
        int qualityPages;
        final String type = (String) request.getSession().getAttribute(
                Constants.ATTRIBUTE_NAME_TYPE);
        if ((type == null) || type.equals("guest") || type.equals("")) {
            request.getRequest().setAttribute(Constants.MESSAGE_ERROR_VIEW,
                    MessageManager.getProperty(Constants.MESSAGE_WRONG_VIEW));
            return ConfigurationManager.getProperty(Constants.PROPERTY_PATH_LOGIN_PAGE);
        }
        try {
            final int startPosition = Integer.parseInt(request.getRequest().getParameter("start"));
            final List<Record> listRecords = ViewLogic.extract(startPosition);
            qualityPages = (int) Math.ceil(ViewLogic.getQualityRecords() / 30.0);
            request.getRequest().setAttribute(Constants.ATTRIBUTE_CURRENT_POSITION, startPosition);
            request.getRequest().setAttribute(Constants.ATTRIBUTE_QUALITY_PAGES, qualityPages);
            request.getRequest().setAttribute(Constants.ATTRIBUTE_NAME_LIST_RECORDS, listRecords);
            page = ConfigurationManager.getProperty(Constants.PROPERTY_PATH_VIEW_PAGE);
        } catch (final ViewException e) {
            request.getRequest().setAttribute(Constants.MESSAGE_ERROR_VIEW,
                    MessageManager.getProperty(Constants.MESSAGE_WRONG_VIEW));
            page = ConfigurationManager.getProperty(Constants.PROPERTY_PATH_VIEW_PAGE);
        }
        return page;
    }

}

JavaScript

Сервлет actionController

/**
 * This servlet process all commands from pages.
 */
@WebServlet("/actionController")
public class ActionController extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
            throws ServletException, IOException {
        processRequest(req, resp);
    }

    @Override
    protected void doPost(final HttpServletRequest req, final HttpServletResponse resp)
            throws ServletException, IOException {
        processRequest(req, resp);
    }

    private void processRequest(final HttpServletRequest request, final HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding(Constants.ENCODING_UTF_8);
        final SessionRequest requestContent = new SessionRequest(request);
        String page = null;
        final ActionFactory client = new ActionFactory();
        final IActionCommand command = client.defineCommand(requestContent);
        // получение страницы ответа (ссылки) по введённой команде Пример: command=view. Выше представлен метод обработки в секции HTML
        page = command.execute(requestContent);
        if (page != null) {
            final RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(page);
            dispatcher.forward(requestContent.getRequest(), response);
        } else {
            page = ConfigurationManager.getProperty(Constants.PROPERTY_PATH_INDEX_PAGE);
            requestContent.insertAttribute(Constants.PARAMETER_NULL_PAGE,
                    MessageManager.getProperty(Constants.MESSAGE_NULL_PAGE));
            response.sendRedirect(requestContent.getRequest().getContextPath() + page);
        }
    }

}