Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending data to a servlet without using forms and doGet()

Status
Not open for further replies.

yodaa

Programmer
Jun 10, 2004
64
SE
Is there a way of sending the current HTML document and an extra parameter to a servlet not using forms? Or sending a a large parameter list with stringvalues etc describing the above.

I thought of sending the data as a fixed URL (/servlet?param=...) and receive it in the servlet with the doGet() method. But as I know of one can only send 255 characters using doGet(). doPost() would maybe fix this, but how do you send data to doPost() without forms.

I'm really stuck here and have no ideas of what to do. Can anybody give me some directions?
 
You can send what you want to a servlet, perhaps using javasript :

document.location = yourURL;

As for the doPost/doGet thing, it is normal practice to implement processing logic in only one of those methods (ie doPost), and just send all requests to doGet to doPost, ie :

Code:
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	// Send any HTTP GET requests to the doPost() method
	doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	// Do some stuff
    }

--------------------------------------------------
Free Database Connection Pooling Software
 
Thanx alot for the quick reply Sedj.

I have another small question. How can I pass an array from a JavaScript in the webpage to the servlet using a POST method? Is this even possible. Using an array that is sent forth and back would really solve my problem. I have been "crying" all day trying to solve this problem but I only seem to hit the wall everytime I come up with a new idea.

Pls, help..
 
You cannot really. You can loop the array in JavaScript and then add each element (as long as it is ascii data) to the parameter list, but cannot send objects via http.

If you had the array in java, *not javascript) you could set it as a session variable, and access it from the JSP and sefvlet easily that way.

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top