Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- public class MyServlet extends HttpServlet {
- public void doPost(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, IOException {
- res.setContentType("text/html");
- PrintWriter out = res.getWriter();
- String username = req.getParameter("username");
- String password = req.getParameter("password");
- if (allowUser(username, password)) {
- out.println("<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD>");
- out.println("<BODY>Your login and password are invalid.<BR>");
- out.println("</BODY></HTML>");
- }
- else {
- out.println("<HTML><HEAD><TITLE>Access Granted</TITLE></HEAD>");
- out.println("<BODY>Your login and password are valid.<BR>");
- out.println("</BODY></HTML>");
- HttpSession session = req.getSession();
- session.setAttribute("logon.isDone", username);
- try {
- String target = (String) session.getAttribute("login.target");
- if (target != null) {
- res.sendRedirect(target);
- return;
- }
- }
- catch (Exception ignored) { }
- //res.sendRedirect("/");
- }
- }
- protected boolean allowUser(String username, String password) {
- return true;
- }
- }
Add Comment
Please, Sign In to add comment