import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* This servlet when receives an http request stores a variable named 'login'
* in Session with value 'login is correct' and provides a link to the ServletB.
*
* @author Sofoklis Stouraitis
*/
public class ServletA extends HttpServlet {
/**
* Handles HTTP GET requests.
*
* @param request
* the request object
* @param response
* the response object
*
* @throws IOException
* if an input or output error is detected when the servlet
* handles the GET request
* @throws ServletException
* if the request for the GET could not be handled
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html; charset=ISO-8859-7");
PrintWriter out = new PrintWriter(response.getWriter(), true);
/*
* Enable Session
*/
HttpSession session = request.getSession(true);
try {
out.println("<html>");
out.println("<head>");
out.println("<Meta Http-Equiv='Content-Type' Content='text/html; Charset=windows-1253'>");
out.println("<title>AddDataToSessionServlet</title>");
out.println("</head>");
out.println("<body bgcolor='#CCFF99'>");
out.println("<h1>ServletA is running...</h1>");
/*
* Store a variable named 'login' in a Session with value
* 'login is correct'
*/
session.setAttribute("login", "login is correct");
out.println("<div align ='center'><h2>Η είσοδος πραγματοποιήθηκε με επιτυχία</h2><br>");
out.println("<h2>Μπορείτε με ασφάλεια να μεταβείτε στο ServletB</h2>");
out.println("<br><a href='ServletB'>Μετάβαση στο ServletB</a>");
out.println("</div></body>");
out.println("</html>");
} catch (Exception ex) {
out.println("Exception: " + ex.getMessage());
out.println("</body>");
out.println("</html>");
}
}
}// End of class
|