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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:14:24+00:00 2026-06-14T19:14:24+00:00

I have next JSP page that works on Google App Engine: <%@ page contentType=text/html;

  • 0

I have next JSP page that works on Google App Engine:

<%@ page contentType="text/html; charset=windows-1251" language="java" %>
<%@ page import="com.wedding.Register" %>

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
        <link href="css/bootstrap.min.css" rel="stylesheet">

        <script src="js/jquery.min.js" type="text/javascript"></script>
        <script src="js/bootstrap.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        function submitMyForm(button) {
            var myForm = $(button).closest('form');
            $.ajax({
                url: $(myForm).attr('action'),
                type: "post",
                contentType:attr("enctype", "multipart/form-data"),
                data: $(myForm).serialize(),
                statusCode: {
                    400: function () {
                        $('.form-inline').after("<h1>400!</h1>");
                    },
                    200: function () {
                        $('.form-inline').after("<h1>200!</h1>");
                    }
                }
            });
        }
    </script>
</head>
<body>
    <div class="container">

    <% 
        String companyName = Register.getLoggedInCompanyName(request);
        if (companyName == null) {
    %>

        <div class="navbar">
          <div class="navbar-inner">
            <a class="brand" href="#">Menu</a>
            <ul class="nav">
              <li><a href="/">Home</a></li>
              <li class="active"><a href="/reg.jsp">Register</a></li>
            </ul>
          </div>
        </div>

        <div class="hero-unit">
            <h1>Login</h1>
            <p>Enter login credentials</p>
            <p>
                  <form action="/reg?action=login" class="form-inline" method="post" enctype="multipart/form-data">
                      <input type="text" name="email" class="input-xlarge" placeholder="">
                      <input type="password" name="password" class="input-xlarge" placeholder="">
                      <button type="submit" class="btn" onClick="submitMyForm(this)">Login</button>
                  </form>
            </p>
        </div>

    <% 
        } else {
    %>

        <div class="navbar">
          <div class="navbar-inner">
            <a class="brand" href="#">Menu</a>
            <ul class="nav">
              <li><a href="/">Home</a></li>
              <li class="active"><a href="/reg?action=logout">Logout</a></li>
            </ul>
          </div>
        </div>

        <div class="hero-unit">
            <h1>Error</h1>
            <p>Error.</p>
        </div>

    <% 
        }
    %>

    </div>

    <div id="footer">
        <div class="container">
            <p class="muted credit"></p>
        </div>
    </div>  
</body>

The problem is that when a click button the form is sent to the server but if the server return 400 HTTP status code

$('.form-inline').after("<h1>400!</h1>");

is not invoked.

I’ve also tried success/error function and other HTTP codes but without success. The interesting thing is that it worked once and then always fails. Instead of adding new element to HTML the browser is redirected to the generated error page.

The status code is returned using

HttpServletResponse.sendError(400);

I’ve checked that a correct request and response are sent. I’ve also checked that the latest jquery is linked.

  • 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-14T19:14:25+00:00Added an answer on June 14, 2026 at 7:14 pm

    A <button/> enclosed in a <form/>, by default, submits it. So, you need to stop the form submission.

    In the following example I will stick with jQuery instead of your mix of JavaScript and jQuery.

    /* Bind the submit event */
    $("form").submit(function() {
      /* Request an HTTP 400 */
      $.ajax({
        url: "http://httpstat.us/400",
        statusCode: {
          400: function() {
            console.log("HTTP 400 received");
          }
        }
      });
      /* stop the form submission */
      return false;
    });​
    

    <form action="/reg?action=login" class="form-inline" method="post" enctype="multipart/form-data">
      ...
      <button type="submit" class="btn">Login</button>
      ...
    </form>
    

    Since $.ajax is executed asynchronously, if you don’t stop the form submission the browser will still submit it hence redirecting the page.

    Feel free to test it out.

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

Sidebar

Related Questions

I have a problem and can't find information. I run my web-app from jsp-page
I have a table on my jsp page that will have a column populated
I have a .jsp page where I have a GUI table that displays records
I have a JSP that submits via javascript to a controller. Everything works fine,
I have a next question. In jsp page I use menu for 2 users
I have a checkbox in a jsp page, when i clicked that checkbox control
I have a java servlet that passes an array to a jsp page, on
I have next 2 blocks of code: def replace_re(text): start = time.time() new_text =
I have been facing some serious issues while executing this particular JSP page. CODE
I have a problem with a jsp page (I'm a novice). In a jsp

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.