Post Requests

By now we should know that a client (such as a web browser) works by sending a request to a server. The server responds to that request with the content of a file (such as an HTML, image, or CSS file) or dynamically created content from a servlet or JSP. The client then renders that content to the user.


This is a companion discussion topic for the original entry at https://happycoding.io/tutorials/java-server/post

So im doing this tutorial and towards the end were building a chat with AJAX and xmlhttprequest to update without refreshing.

When you go the Ajax and Json tutorial it says its outdated and instead of using the xmlhttprequest youre better of using fetch and redirects to the fetch tutorial. In the fetch tutorial it only shows how to load urls and jsons. Is it possible to do a post or get request using fetch and getting data from a servlet and building the self-updating chat with fetch?

Yeah, it’s definitely possible to make a POST request using the fetch function!

I never remember the syntax, so I would google something like “JavaScript fetch post” which returns a few helpful results, including this one:

@Meisel btw, I just updated this tutorial to include an example of using the fetch() function to send a POST request. Let me know if that makes sense!