Sending HTTP Requests without Reloading and without AJAX
Supposing I have a simple HTML form that looks like this:
<form method="post" action="/SomeServlet"> <input type="text" name="message" value="Hello Server" /> <input type="submit" value="Send" /> </form>
And supposing I have a Servlet mapped at the path /SomeServlet, consisting of the code:
public class SomeServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println(request.getParameter("message")); response.setStatus(HttpServletResponse.SC_NO_CONTENT); } }
If I goto the form, type in a message, and click the Send button, the message will print out on the Server's console. So What? So the cool thing is the HTML Form is not reloaded. Which could be useful if you've got heavy data on it. Seriously! Fire up Fiddler and watch your HTTP traffic.
Of course there are many other ways of doing this, a lot of them with Javascript or IFrames. This one does not require the use of anything fancy on the client side. Just an HTML Form. And of course it works outside of Java Servlets too-- so long as you can mess around with the HTTP status code.