Forums Register Login
writing HTML in servlet
I am writing html code in servlet as given below:::

StringBuffer oStringBuffer = new StringBuffer();
oStringBuffer.append("<form name=\"motoForm\" action=\"/vbv/MPIEntry.jsp\" method=\"POST\" >");
oStringBuffer.append("<input type=hidden name=\"shoppingContext\" value=\"" + this.requestID + "\">");
oStringBuffer.append("<input type=hidden name=\"pan\" value=\"" + this.cardNumber + "\">");
oStringBuffer.append("<input type=hidden name=\"expirydate\" value=\"" + this.expiry + "\">");
oStringBuffer.append("<script language=javascript>window.onload = function() { document.forms[0].submit(); }</script>");

but when i run servlet it do not call jsp page.
What do you mean by "call JSP page"? The servlet just writes some text, it doesn't call (or forward to) anything.
For writing HTML in the servlet you make use of PrintWriter.

Refer its API here.

Ashwini Kashyap
Hey Ashwini, Thanks for your help....:)
Its working now we can use as follows::

PrintWriter out = response.getWriter();
out.println("<form name=\"motoForm\" action=\"/abc.jsp\" method=\"POST\" >");
out.println("<input type=hidden name=\"shoppingContext\" value=\"" + this.requestID + "\">");
out.println("<script language=javascript>window.onload = function() { document.forms[0].submit(); }</script>");

and it directly calls that jsp.
Thats great!!! You're welcome :)

Ashwini Kashyap
The form gets submitted immediately when the page is loaded - is that correct? Can't you just do a redirect from within the servlet? Why the form submit?
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Rocket Oven Kickstarter - from the trailboss

This thread has been viewed 5505 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 19, 2018 23:09:48.