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 833435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:31:04+00:00 2026-05-15T04:31:04+00:00

How do you stop a JSP from executing? I have JSPs which kick the

  • 0

How do you stop a JSP from executing?

I have JSPs which kick the user off a page by means of a “forward”.

public boolean kickIfNotLoggedIn(
        HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    //code to check if user is logged in
    req.getRequestDispatcher(
            ACCESS_DENIED_PAGE).forward(request, response);
}

In my JSP, I have this code, BEFORE any HTML output:

<%
            //loginHelper.kickIfNotLoggedIn(request, response);
            if (!loginHelper.kickIfNotLoggedIn(request, response)) {
                return;
            }
%>

If I don’t use the return statement, the JSP continues processing, and I get a NullPointerException. If I use the return statement (as is commonly suggested on various sources on the net), I get an IllegalStateException:

StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: PWC3991: getOutputStream() has already been called for this response
        at org.apache.coyote.tomcat5.CoyoteResponse.getWriter(CoyoteResponse.java:717)
        at org.apache.coyote.tomcat5.CoyoteResponseFacade.getWriter(CoyoteResponseFacade.java:226)
        at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:187)

Any ideas how to fix this, or another way to achieve an access denied page?

Thanks

  • 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-05-15T04:31:04+00:00Added an answer on May 15, 2026 at 4:31 am

    You can’t do it this way. The error message is a bit unclear but it has to do with starting rendering a response in one resource, stopping, then forwarding on to another resource which tries to restart processing of the HTTP response.

    Use a servlet Filter instead, in front of all JSPs that need login, to redirect before any JSP even touches the response.

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

Sidebar

Related Questions

How do I stop my application from going back when the user clicks on
This could be a repeat question, I apologize. I have a jsp page in
I have developed a JSP web application which, on every request, spawns a new
I'm calling a JavaScript function from an onclick event in a JSP page. <%
I have a text area which I need to prevent from having javascript entered.
I have two jsp pages and one servlet. When user clicks submit button then
I've got a JSP page, which calls a function and checks its return value.
Stop a thread like: new Thread ( new Runnable() { public void run(){ if
I want to stop the end users from being able to resize a GUI
how to I stop a Video from playing and go back to start? videoPlayer.currentPlaybackTime

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.