Package com.tubeonfire.controller

Source Code of com.tubeonfire.controller.AuthorServlet

package com.tubeonfire.controller;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tubeonfire.search.TubeSearchModel;

@SuppressWarnings("serial")
public class AuthorServlet extends HttpServlet {

  private static final Logger log = Logger.getLogger(AuthorServlet.class
      .getName());

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    try {
      String[] splitted = req.getRequestURI().split("/");
      String author = "";
      if (splitted.length == 3) {
        author = splitted[2];
      } else {
        resp.sendRedirect("/home");
      }
      int page = 1;
      try {
        page = Integer.parseInt((String) req.getParameter("page"));
      } catch (Exception e) {
        page = 1;
      }     
      TubeSearchModel model = new TubeSearchModel();
      model.setPage(page);
      model.prepareTubeByAuthor(author);
      req.setAttribute("model", model);
      req.setAttribute("author", author);
      req.setAttribute("url", req.getRequestURL().toString());
      req.getRequestDispatcher("/author.jsp").forward(req, resp);     
    } catch (Exception e) {
      log.warning(e.toString());
      e.printStackTrace();
      resp.sendError(4000,
          "Website is down for maintenance. We are sorry for the inconvenience !");
    }
  }
}
TOP

Related Classes of com.tubeonfire.controller.AuthorServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.