I'm trying to understand a very simple example of using html + servlets using Eclipse EE.

I have an index.html :

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Ze title!</title>


	<form action="MyServlet" method = post>
		<input type= text name = text>
		<input type = submit value="Submit">


And a servlet named MyServlet:

package test;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public MyServlet() {
        // TODO Auto-generated constructor stub

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		PrintWriter out = response.getWriter();
		String s=(String) request.getParameter("text");
		out.print("<head><title>Added title</title></head>");

		out.print("input= "+s+"  this is the GET method");

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		String s=(String) request.getAttribute("text");
		out.print("input= "+s+"  this is the POST method");

So I have a doGet and a doPost method. If I use:

<form action="MyServlet" method = post>

in my index.html, the Eclipse browser still executes the GET method, while Opera uses the POST method. Why is this?

Furthermore, can I add more methods in my servlet and call them from my html?

<form action="MyServlet" method = FooMethod>

Now that I've put it in writing, it does look pointless. In the tutorials I've found, I've only seen adding more methods but calling them from within the GET/POST methods, not directly.


Edited by Buffalo101: n/a

7 Years
Discussion Span
Last Post by Airshow

Depending on DOCTYPE, Eclipse has the right to be picky over badly formed HTML.

Assuming XHTML, attributes should be in "double quotes".

This may fix it:

<form action="MyServlet" method="post">


Edited by Airshow: n/a



It was just a thought.

I can't immediately see how doGet/doPost is called - presumably in HttpServlet. Can you intercept the logic and see where it breaks down?



Sorry for sounding rude, Airshow.

Well, my problem with running the doGet / doPost methods is still here. I'll quote something I found about the two methods:


In doget() method there is a security problems are arrival because when the user or client submit the form the associated user name or password has been display on the addressbar.

but in case of doPost() method when the user submit the form the associated user name or password are not display on the addressbar.


by doget() method client can send limited amount of data.

but in case of dopost() method client can send more then data as compare to doget() method.

doGet is used when there is are requirement of sending dataappended to a query string in the URL. The doGet models the GET methodof Http and it is used to retrieve the info on the client from some server as arequest to it.The doGet cannot be used to send too much info appended as a querystream. GET puts the form values into the URL string. GET is limited toabout 256 characters (usually a browser limitation) and creates reallyugly URLs.

POST allows you to have extremely dense forms and pass that to theserver without clutter or limitation in size. e.g. you obviously can'tsend a file from the client to the server via GET.

POST has no limit on the amount of data you can send and because thedata does not show up on the URL you can send passwords. But this doesnot mean that POST is truly secure. For real security you have to lookinto encryption which is an entirely different topic

Depending on the request type (get or post) container invokes the corresponding doGet() or doPost() method by default the request type is get and the container looks for doGet() method.

preferabily for posting data through form post is used and for getting data from server side preferabily get is used get is fastt than post request get transfers data through url and hence not safe post transfer data as a body or in the form of packets get can transfer limited data post has no such limitation.

Well, okay. But if I request the POST function in my HTML file, why does GET run?

<form action="MyServlet" method = post>
		<input type= text name = text>
		<input type = submit value="Submit">

If anyone has a good example of how the two methods are used, please link me up.

Thank you.



My guess is still that a GET request is being issued despite METHOD = post . In other words the problem is with Eclipse not the servlet.

Looking through the eclipse.com/forums a number of form submission problems seem to arise.

Can you enquire your server logs to inspect the request?
Can you try a different browser (FF, IE, Opera etc) to submit the form? (If necessary create a separate test page with hard-coded absolute action="http://......" )



My only conclusion is that the Eclipse browser is retarded.

Opera and IE perform normally, while the Eclipse browser fails at everything.

For instance, I modified my HTML to have this:

<form action="MyServlet" method = "get">

		<input type= text name = text><br>
		<input type= text name = name><br>
		<input type = submit value="Submit">


You would expect Eclipse to display a form with 2 fields, like Opera and IE. But that's not the case. I think I'll just forget about it and use a normal browser.




Edited by Buffalo101: n/a


Turns out, the Eclipse browser DOES work for a brief time after closing & opening it again. Stopping the server, saving all the files, publishing etc - nothing worked before.

Since I have now cleared the initial problems stated, I am marking this as solved. Thanks Airshow.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.