The debugger successfully displayed the HTML page in the POST response, but it was not visible in the browser when

Having an issue with my connection form that is sending a Post request to a servlet. The servlet then forwards the request to different pages after performing some tests such as password and email verification of the user. However, the problem I am facing is that although I receive the correct page as a response when checking my POST request, it doesn't display in my web browser. Any idea why?

Below is my code:

Sign In Servlet

Code snippet for sign-in servlet goes here...

signIn.jsp

Code snippet for signIn.jsp goes here...

SignIn Class

Code snippet for SignIn class goes here...

In the signIn.jsp file, I have ${connect.error} which should display the error message. However, while using the debugger I can see this message being displayed, but not on my web browser. After the POST request, it seems to stay on the same web page path and only the HTML is shown in the response.

EDIT

Attached below is a screenshot:

https://i.stack.imgur.com/FPOhv.jpg Any assistance on this matter would be highly appreciated.

Answer β„–1

Although I'm not very familiar with angular, by referring to the w3 site for AJAX, you will need to handle the response in a similar manner:

Make sure to add an ID to your span element (remove ${connect.error} from it):

<span id="somediv"></span>

Include a "then" function for success:

<script type="text/javascript>
        var app = angular.module("AHS", []);
        app.controller("myCtrl", function ($scope, $http, $httpParamSerializerJQLike){
            $scope.userObj = {
                    mail: "",
                    password: "",
            }
            $scope.submitForm = function() {
                  $http({
                     method : 'POST',
                     url : '/', // use relative
                     data: $httpParamSerializerJQLike($scope.userObj),
                     headers: {
                       'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8;'
                     }
                  }).then(function mySuccess(response) {
                      //handle response here
                      console.log(response.data);
                      document.getElementById("somediv").innerHTML = response.data;
                  });
                };
        });
    </script>

As for your servlet code:

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
    signInForm connect = new signInForm();
    User user = connect.validateSignIn(request);
    HttpSession session = request.getSession();

    if (user != null) {
       // request.setAttribute("connect", connect); //what is 'connect' used for here?
        session.setAttribute("sessionUser", user);
       // this.getServletContext().getRequestDispatcher("/restrict_client/client.jsp").forward(request, response); //avoid doing this in AJAX requests.
    }else{
    //request.setAttribute("connect", connect);
     //this.getServletContext().getRequestDispatcher("/signIn.jsp").forward(request, response);
    }
    response.setContentType("text/plain");  // Set content type 
    response.setCharacterEncoding("UTF-8"); 
    response.getWriter().write("hello world");       // Write response body.

}

EDIT:

To learn more about using AJAX and Servlets, check out this helpful answer on StackOverflow:

How to use Servlets and Ajax?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for loading a webpage into another webpage with google app engine?

Hey there, I'm a newbie to app engine and could really use some help, I'm looking to replicate the functionality of the jquery load function on the server side within a RequestHandler's get() method. Currently, I have a page that looks some ...

Guide to setting a limit on image size using get_serving_url

When working with images, I noticed that some exceed the desired maximum width and height. Is there a method to specify the image size limit using get_serving_url()? ...

Building a custom DSL expression parser and rule engine

In the process of developing an app, I have included a unique feature that involves embedding expressions/rules within a configuration yaml file. For instance, users will be able to reference a variable defined in the yaml file using ${variables.name == &a ...

What methods can programming languages use to direct the Lua (or Python) interpreter to run commands specified by the program?

I am currently running on an operating system called Cent OS 7. I have a desire to develop a program, which may be written in Java or another language, that can communicate with the Lua interpreter. It is my goal for this program to send commands to the L ...

Creating a Docker container to execute Python3 from a Node.js child_process on Google App Engine

I have been working on deploying a node.js web application using a custom runtime with flex environment. In my code, I am calling child_process in Node.js to open python3 like so: const spawn = require("child_process").spawn; pythonProcess = spawn('p ...

The process of saving a model in Django

It has come to my attention that there is no assurance that the database will be updated synchronously following a call to save() on a model. To test this, I conducted a simple experiment by sending an ajax call to the method below: def save(request, id) ...

Is there a continuous integration system available that supports Java, Python, and Ruby?

We have a range of technology tools at our disposal, including Java, Python, and Ruby code (and no, we're not Google ;-) ). Any recommendations for a good CI framework to use? Hudson or something else? dwh ...

How to interact with AngularJS drop-down menus using Selenium in Python?

I have been working on scraping a website to create an account. Here is the specific URL: Upon visiting the site, you need to click on "Dont have an account yet?" and then click "Agree" on the following page. Subsequently, there are security questions th ...

Unlock hidden messages by deciphering the Ascii string values within a lua file that has been

After decompiling a lua file using unluac, I discovered that all the string variables are no longer readable and are now ascii encoded clues = { { answer = { "\216\173", "\216\177", "\216\168", " ...

What are the steps to integrate gaeunit 2.0a with my Django application?

I'm currently in the process of setting up unit testing on Google App Engine for my web application. After downloading the necessary file from this link, I followed the instructions provided in the readme. As instructed, I copied the 'gaeunit&ap ...

What is the reason that dynamic languages do not have a requirement for interfaces?

In Python, do we not need the concept of interfaces (like in Java and C#) simply because of dynamic typing? ...

When using Eclipse, each workspace must have a unique project name in order to save properly

Hey there! I've done some research on this topic already. It seems that in Eclipse, if you utilize different workspaces, you should be able to save projects with the same name. However, I am encountering difficulties in doing so and I'm not sure ...

Google Appengine login authorization

Whenever a user accesses the application, I would like to execute a specific action, such as recording the login timestamp. I am curious to know if there is a default hook triggered upon login. If so, how can my module be programmed to react to it. Edit - ...

Regular expression: Rearrange the order of matches within a capturing group

To successfully extract user identities from a smartcard, I must adhere to the pattern format: CN=LAST.FIRST.MIDDLE.0000000000 The desired result should be: FIRST.LAST If this process were implemented in my own code, it would be straightforward: # Sampl ...

Encountering a CORS header issue while working with the Authorization header

Here is the code snippet I am currently working with: https://i.stack.imgur.com/DYnny.png Removing the Authorization header from the headers results in a successful request and response. However, including the Authorization header leads to an error. http ...

What causes the differing behaviors of strptime and strftime, and how can you address this discrepancy?

Currently working with Python 2.5 in an App Engine environment, I am implementing pagination using the following code: NEXT_FORMAT = "%Y-%m-%d %H:%M:%S" current = model.completed_on.strftime(NEXT_FORMAT) completed_before = datetime.datetime.strptime(cur ...

Encountering a coding issue in Arabic when utilizing the requests RESTful client

Below is a Python code snippet for a RESTful client: import requests; s= 'This is the message to be sent'; resp = requests.post('http://localhost:8080/MyApp/webresources/production/sendMessage', json={'message': s,} ) This c ...

Google App Engine: β€œAn error occurred: Unable to connect to /_ah/remote_api/Endpoint: 404 error status.”

Hello Friends, I recently started using Google App Engine and have been learning on my own. However, I have encountered an issue that I need help with. I am attempting to copy entities from one app to another by selecting all the entities and clicking ...

LibGDX's latest project featuring a vibrant yellow warning triangle

Recently, I embarked on a new endeavor with LibGDX. While normally I overlook the presence of yellow warning triangles in my projects, this time it has become somewhat bothersome. Is there a way to address this issue? Here is a visual representation: ...