Example usage for javax.servlet.http HttpSession getId

List of usage examples for javax.servlet.http HttpSession getId

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession getId.

Prototype

public String getId();

Source Link

Document

Returns a string containing the unique identifier assigned to this session.

Usage

From source file:SessionLogin.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Login</title>");
    out.println("</head>");
    out.println("<body>");

    HttpSession session = request.getSession();
    SessionConnection sessionConnection = (SessionConnection) session.getAttribute("sessionconnection");
    Connection connection = null;
    if (sessionConnection != null) {
        connection = sessionConnection.getConnection();
    }//www  . j  av  a  2s  .  co m
    if (connection == null) {
        String userName = request.getParameter("username");
        String password = request.getParameter("password");
        if (userName == null || password == null) {
            // prompt the user for her username and password
            out.println("<form method=\"get\" action=\"SessionLogin\">");
            out.println("Please specify the following to log in:<p>");
            out.println("Username: <input type=\"text\" " + "name=\"username\" size=\"30\"><p>");
            out.println("Password: <input type=\"password\" " + "name=\"password\" size=\"30\"><p>");
            out.println("<input type=\"submit\" value=\"Login\">");
            out.println("</form>");
        } else {
            // create the connection
            try {
                connection = DriverManager.getConnection("jdbc:oracle:thin:@dssw2k01:1521:orcl", userName,
                        password);
            } catch (SQLException e) {
                out.println("Login doGet() " + e.getMessage());
            }
            if (connection != null) {
                // store the connection
                sessionConnection = new SessionConnection();
                sessionConnection.setConnection(connection);
                session.setAttribute("sessionconnection", sessionConnection);
                response.sendRedirect("SessionLogin");
                return;
            }
        }
    } else {
        String logout = request.getParameter("logout");
        if (logout == null) {
            // test the connection
            Statement statement = null;
            ResultSet resultSet = null;
            String userName = null;
            try {
                statement = connection.createStatement();
                resultSet = statement.executeQuery("select initcap(user) from sys.dual");
                if (resultSet.next())
                    userName = resultSet.getString(1);
            } catch (SQLException e) {
                out.println("Login doGet() SQLException: " + e.getMessage() + "<p>");
            } finally {
                if (resultSet != null)
                    try {
                        resultSet.close();
                    } catch (SQLException ignore) {
                    }
                if (statement != null)
                    try {
                        statement.close();
                    } catch (SQLException ignore) {
                    }
            }
            out.println("Hello " + userName + "!<p>");
            out.println("Your session ID is " + session.getId() + "<p>");
            out.println("It was created on " + new java.util.Date(session.getCreationTime()) + "<p>");
            out.println("It was last accessed on " + new java.util.Date(session.getLastAccessedTime()) + "<p>");
            out.println("<form method=\"get\" action=\"SessionLogin\">");
            out.println("<input type=\"submit\" name=\"logout\" " + "value=\"Logout\">");
            out.println("</form>");
        } else {
            // close the connection and remove it from the session
            try {
                connection.close();
            } catch (SQLException ignore) {
            }
            session.removeAttribute("sessionconnection");
            out.println("You have been logged out.");
        }
    }
    out.println("</body>");
    out.println("</html>");
}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/UpdateInformation", method = RequestMethod.POST)
public String updateInformation(HttpServletRequest request, HttpSession session) {
    try {//w  w  w .jav  a 2  s . co  m
        AccountSession account = providerService.updateProviderInformation(request, session);
        request.getSession().setAttribute("account", account);
        if (request.getParameter("language") != null) {
            return "redirect:/Provider/AccountInfo" + "?language=" + request.getParameter("language");
        } else {
            return "redirect:/Provider/AccountInfo";
        }

    } catch (Exception e) {
        String content = "Function: ProviderController - updateInformation\n" + "****Error****\n"
                + e.getMessage() + "\n" + "**********";
        request.setAttribute("errorID", session.getId());
        request.setAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/PreView/{packageID}", method = RequestMethod.POST)
public String getPackagePreviewPage(@PathVariable("packageID") int packageID, HttpSession session,
        ModelMap model) {//from  ww  w.j a  v a  2 s  . co  m
    try {
        String reportType = commonService.getReportType();
        String json = providerService.getTemporaryPackageForPreviewing(packageID, false);
        model.addAttribute("packageDTO", json);
        model.addAttribute("ReportType", reportType);
        model.addAttribute("isFinished", false);
        model.addAttribute("toDate", commonService.getToDateUnderFormatMMddyyyy());
        return "provider/packagePreview";
    } catch (Exception e) {
        String content = "Function: ProviderController - getPackagePreviewPage\n" + "****Error****\n"
                + e.getMessage() + "\n" + "**********";
        model.addAttribute("errorID", session.getId());
        model.addAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/PreViewEditing", method = RequestMethod.POST)
public String previewEditing(HttpServletRequest request, HttpSession session, ModelMap model) {
    try {//from  w w w.  j a  v a 2s.  co  m
        String packageIDStr = request.getParameter("packageID");
        int packageID = Integer.parseInt(packageIDStr);

        String reportType = commonService.getReportType();
        request.setAttribute("ReportType", reportType);
        model.addAttribute("packageDTO", commonService.getPreviewPackageEditing(packageID));
        model.addAttribute("toDate", commonService.getToDateUnderFormatMMddyyyy());
        return "provider/editPackagePreview";
    } catch (Exception e) {
        String content = "Function: ProviderController - previewEditing\n" + "****Error****\n" + e.getMessage()
                + "\n" + "**********";
        model.addAttribute("errorID", session.getId());
        model.addAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/DeleteCertificate/{CertificateID}", method = RequestMethod.GET)
public String deleteCertificate(@PathVariable int CertificateID, HttpSession session, ModelMap map,
        HttpServletRequest request) {/* www.  j av a 2  s  .  c o m*/

    try {
        providerService.deleteCertificate(CertificateID, session);
        if (request.getParameter("language") != null) {
            return "redirect:/Provider/CertificateManagement" + "?language=" + request.getParameter("language");
        } else {
            return "redirect:/Provider/CertificateManagement";
        }

    } catch (Exception e) {
        String content = "Function: UserController - deleteCertificate\n" + "***Input***\n" + "CertificateID: "
                + CertificateID + "\n" + "**********\n" + "****Error****\n" + e.getMessage() + "\n"
                + "**********";
        map.addAttribute("errorID", session.getId());
        map.addAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        if (request.getParameter("language") != null) {
            return "redirect:/Provider/CertificateManagement" + "?language=" + request.getParameter("language");
        } else {
            return "redirect:/Provider/CertificateManagement";
        }

    }

}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/Package/PreViewv2/{packageID}", method = RequestMethod.GET)
public String goToPreviewv2(@PathVariable("packageID") int packageID, HttpSession session, ModelMap model) {
    try {/*  w  w w.j av  a2  s  .co m*/
        String reportType = commonService.getReportType();
        String json = providerService.getTemporaryPackageForPreviewingv2(packageID, true);
        model.addAttribute("ReportType", reportType);
        // if temporary package data is not correct
        if (json.equals("fail")) {
            return "forward:/Provider/Package/Creation/";
        } else {
            model.addAttribute("temporaryPackage", json);
            return "provider/previewPagev2";
        }
    } catch (Exception e) {
        String content = "Function: ProviderController - goToPreviewv2\n" + "****Error****\n" + e.getMessage()
                + "\n" + "**********";
        model.addAttribute("errorID", session.getId());
        model.addAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}

From source file:de.sub.goobi.metadaten.Metadaten.java

/**
 * Get image.//from  w  w  w .  j a v  a2 s .c  o m
 *
 * @return String
 */
public String getBild() {
    checkImage();
    /* Session ermitteln */
    FacesContext context = FacesContext.getCurrentInstance();
    HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
    return ConfigCore.getTempImagesPath() + session.getId() + "_" + this.imageCounter + ".png";
}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/Chat", method = RequestMethod.GET)
public String gotoChat(HttpServletRequest request, ModelMap map) {
    try {/*ww w  .java2  s.  co  m*/
        HttpSession session = request.getSession();
        request.setAttribute("page", "providerMessage");
        String conversationList = "";
        String packageList = "";
        AccountSession account = (AccountSession) session.getAttribute("account");
        packageList = providerService.getPackageForChat(account.getId());
        conversationList = messageService.providerLoadConversationList(account.getId());

        request.setAttribute("conversationList", conversationList);
        request.setAttribute("packageList", packageList);
        return "provider/chat";
    } catch (Exception e) {
        HttpSession session = request.getSession();
        String content = "Function: ProviderController - gotoChat\n" + "****Error****\n" + e.getMessage() + "\n"
                + "**********";
        map.addAttribute("errorID", session.getId());
        map.addAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/Package/Deletion/{packageID}", method = RequestMethod.GET)
public String deletePackage(ModelMap model, HttpSession session, @PathVariable int packageID) {
    try {//  w w w  . j  a  va 2s .c  om
        boolean result = providerService.deletePackage(packageID);
        AccountSession account = (AccountSession) session.getAttribute("account");
        model.addAttribute("packages", providerService.getPackagesOfProvider(account.getId()));
        model.addAttribute("page", "providerPackage");
        if (result) {
            model.addAttribute("message", "Delete Package Successfully");
        } else {
            model.addAttribute("message", "You can not delete package which contain active booking");
        }
        return "provider/providerPackage";

    } catch (Exception e) {
        String content = "Function: ProviderController - deletePackage\n" + "****Error****\n" + e.getMessage()
                + "\n" + "**********";
        model.addAttribute("errorID", session.getId());
        model.addAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}

From source file:Controller.ProviderController.java

@RequestMapping(value = "/PreView", method = RequestMethod.POST)
public String getPackagePreview(HttpServletRequest request, HttpSession session, ModelMap model) {
    try {/* www  . j  a  v  a  2s  . co m*/
        String packageIDStr = request.getParameter("packageID");
        int packageID = Integer.parseInt(packageIDStr);
        System.out.println("tien");
        String reportType = commonService.getReportType();
        String json = providerService.getTemporaryPackageForPreviewing(packageID, false);
        model.addAttribute("packageDTO", json);
        model.addAttribute("ReportType", reportType);
        model.addAttribute("isFinished", false);
        model.addAttribute("toDate", commonService.getToDateUnderFormatMMddyyyy());
        return "provider/packagePreview";
    } catch (Exception e) {
        String content = "Function: ProviderController - getPackagePreview tien\n" + "****Error****\n"
                + e.getMessage() + "\n" + "**********";
        model.addAttribute("errorID", session.getId());
        model.addAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}