Friday, September 2, 2016

Get Hostname, port no. & protocol from the http Servlet





    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

        doPost(req, res);
        System.out.println("APP-DEBUG: " + new Timestamp(date.getTime()) + " Leaving doGet()...");
    }

    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        System.out.println("APP-DEBUG: " + new Timestamp(date.getTime()) + " Entering doPost()...");
        // initialize variables and the servlet environment
        int i = 0;
        int lineNumber = 0;
        int errorCount = 0;
        Connection conn = null;
        res.setContentType("text/html");
        HttpSession session = req.getSession();
        System.out.println("Http Session................" + session.getAttribute("pUserId"));
        
        String userId = session.getAttribute("pUserId").toString();
        this.printMessage(req);
}



   public void printMessage(HttpServletRequest req) {

        // initialize variables for page attributes
        // these variables must match those set in apputil.stdhead to
        
         int httpPort = req.getServerPort();
        String serverHost = req.getServerName();
        String httpProtocol = req.getScheme();

System.out.println("httpPort"+httpPort+""+"serverHost "+serverHost+"httpProtocol "+httpProtocol );
}

No comments: