ProtectedResource.java 1.05 KB
Newer Older
1 2 3 4
package com.roshka.proyectofinal;

import java.io.*; 
import java.util.*; 
Emanuel Lugo committed
5
import jakarta.servlet.*;
Angel Zarate committed
6 7
import jakarta.servlet.http.*;

8 9
public class ProtectedResource extends HttpServlet {

Angel Zarate committed
10
	public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
			res.setContentType("text/plain");
			PrintWriter out = res.getWriter();

			// Get the session
			HttpSession session = req.getSession(true);

			// Does the session indicate this user already logged in?
			Object done = session.getValue("logon.isDone");
			// marker object
			if (done == null) {
				// No logon.isDone means he hasn't logged in. // Save the request URL as the true target and redirect to the login page
				session.putValue("login.target",
						HttpUtils.getRequestURL(req).toString()); res.sendRedirect(req.getScheme() + "://" + req.getServerName() + ":"
							+ req.getServerPort() + "/login.html");
				return;
			}
			// If we get here, the user has logged in and can see the goods
			out.println("Unpublished O'Reilly book manuscripts await you!");
		}
	 }