Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8942701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:34:45+00:00 2026-06-15T11:34:45+00:00

I have the following code in JSP: <% if(session.getAttribute(Username) == null || session.getAttribute(Username) ==

  • 0

I have the following code in JSP:

<%
    if(session.getAttribute("Username") == null || session.getAttribute("Username") == "_INVALID_")
    {
        response.sendRedirect("LoginPage.html");
    }
%>

<form>
    <input type="button" value="Change Account Details" onClick="location.href='ChangeDetails.jsp'">
    <br></br>
    <input type="button" value="Add Customers" onClick="location.href='AddCustomers.jsp'">
    <br></br>
    <input type="button" value="Manage Flights" onClick="location.href='ManageFlights.jsp'">
    <br></br>
    <input type="button" value="Book Flights" onClick="location.href='BookFlights.jsp'">
    <br></br>
    <input type="button" value="Log Out" onClick="location.href='LoginPage.html'">
</form>

When the user clicks on the log out button, I want to redirect him to the log-in page and kill the current session. I have succeeded in the redirection part but I do not know how to kill the session. How can this be done please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:34:47+00:00Added an answer on June 15, 2026 at 11:34 am

    In order to kill the current session, you basically need to call HttpSession#invalidate() and perform a redirect to the login or main page. This code is supposed to be placed in doPost() method of a servlet which is invoked by a POST request.

    E.g.

    <form action="${pageContext.request.contextPath}/logout" method="post">
        <input type="submit" value="Logout" />
    </form>
    

    with

    @WebServlet("/logout")
    public class LogoutServlet extends HttpServlet {
    
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.getSession().invalidate();
            response.sendRedirect(request.getContextPath() + "/LoginPage.html");
        }
    
    }
    

    Unrelated to the concrete problem, your username checking code is not at the right place. You shouldn’t be copypasting the same code over every single JSP page. You should be performing this job in a single place in a servlet filter. Java code in JSP files should be avoided as much as possible.

    Further, there’s another potential problem when the enduser uses the browser’s back button to navigate back in history. By default, the browser will cache all responses and thus the back button might display the page from the browser cache instead of requesting a brand new straight from the server. In order to fix this, see this related question Prevent user from seeing previously visited secured page after logout

    Last but not least, you’ve there some quite strange HTML. Buttons with onClick to navigate? How user and SEO unfriendly. Use normal <a> links instead. For the button look’n’feel, throw in some CSS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: index.jsp: <form name=f action=db/ajoutConducteur.jsp method=post> <input type=text pattern=\d{8} required
I have the following JSP code: <c:forEach items=${requestScope.XX} var=x> <tr> <td><input type=radio value=${x.xID} name=x></td>
Just need a small help with my HTML form, I have the following code:
I have following page with code as below embeded in JSP. <!DOCTYPE HTML PUBLIC
I have following line of code for jsp tag <input name=UnicodeVirtualKey class=btn type=button value=&#x0A85;
I have following HTML code in my JSP page: <label class=txt12Red>Label 1</label> <label class=txt12Red>Label
I have the following code. <s:push value=#session['person']> <s:if test=%{admin=='y'}> <a class=add href=/projit1/project/addProject.jsp>Create a Project</a>
I have the following code in a jsp page (Struts backed): <c:if test=${USERINFO.someproperty ==
i am new in JSP,i have some problem with the following code : <%@
I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.