From d39d1bf69b4de2d8f12d4a7547cd9f7938dc1a52 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Sat, 8 Mar 2014 17:34:53 +0700 Subject: Errors.doGet404 --- src/java/com/juick/http/www/Discover.java | 4 +-- src/java/com/juick/http/www/Errors.java | 47 +++++++++++++++++++++++++++++++ src/java/com/juick/http/www/Help.java | 8 +++--- src/java/com/juick/http/www/Home.java | 2 +- src/java/com/juick/http/www/Main.java | 14 ++++----- src/java/com/juick/http/www/SignUp.java | 2 +- src/java/com/juick/http/www/User.java | 4 +-- 7 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 src/java/com/juick/http/www/Errors.java (limited to 'src/java/com/juick/http') diff --git a/src/java/com/juick/http/www/Discover.java b/src/java/com/juick/http/www/Discover.java index 7fd232a2..d80bffdc 100644 --- a/src/java/com/juick/http/www/Discover.java +++ b/src/java/com/juick/http/www/Discover.java @@ -47,7 +47,7 @@ public class Discover { paramTag = TagQueries.getTag(sql, paramTagStr, false); } if (paramTag == null) { - response.sendError(404); + Errors.doGet404(sql, request, response); return; } @@ -68,7 +68,7 @@ public class Discover { response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { - String canonical = ""; + String canonical = null; if (!paramTag.Name.equals(paramTagStr) && paramBefore == 0) { canonical = ""; } diff --git a/src/java/com/juick/http/www/Errors.java b/src/java/com/juick/http/www/Errors.java new file mode 100644 index 00000000..c1ffc2e8 --- /dev/null +++ b/src/java/com/juick/http/www/Errors.java @@ -0,0 +1,47 @@ +package com.juick.http.www; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * + * @author ugnich + */ +public class Errors { + + public static String tagsHTML = null; + + public static void doGet404(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + com.juick.User visitor = Utils.getVisitorUser(sql, request, response); + + if (tagsHTML == null) { + tagsHTML = PageTemplates.getPopularTags(sql, 80); + } + + response.setStatus(404); + response.setContentType("text/html; charset=UTF-8"); + PrintWriter out = response.getWriter(); + try { + PageTemplates.pageHead(out, "404 Страница не найдена", null); + PageTemplates.pageNavigation(out, visitor, null); + + out.println(""); + + out.println("
"); + out.println("

Страница не найдена

"); + out.println("

Сожалеем, но страницу с этим адресом удалил её автор, либо её никогда не существовало.

"); + out.println("
"); + + PageTemplates.pageFooter(request, out, visitor, false); + PageTemplates.pageEnd(out); + } finally { + out.close(); + } + } +} diff --git a/src/java/com/juick/http/www/Help.java b/src/java/com/juick/http/www/Help.java index e69b93a7..eed62efa 100644 --- a/src/java/com/juick/http/www/Help.java +++ b/src/java/com/juick/http/www/Help.java @@ -43,14 +43,14 @@ public class Help { String path[] = request.getRequestURI().split("/"); String page; if (path.length < 3 || path.length > 4 || path[2].length() != 2 || !path[2].matches("^[a-z]+$")) { - response.sendError(404); + Errors.doGet404(sql, request, response); return; } if (path.length == 4) { page = path[3]; if (!page.matches("^[a-zA-Z0-9\\-]*$") || page.equals("navigation") || page.equals("index")) { - response.sendError(404); + Errors.doGet404(sql, request, response); return; } } else { @@ -59,14 +59,14 @@ public class Help { File f = new File("/var/www/juick.com/help/" + path[2] + "/" + page); if (!f.isFile()) { - response.sendError(404); + Errors.doGet404(sql, request, response); return; } response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try { - PageTemplates.pageHead(out, "Помощь", ""); + PageTemplates.pageHead(out, "Помощь", null); PageTemplates.pageNavigation(out, visitor, null); out.println("