Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

writing HTML in servlet  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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>");
oStringBuffer.append("</form>");

but when i run servlet it do not call jsp page.
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "call JSP page"? The servlet just writes some text, it doesn't call (or forward to) anything.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For writing HTML in the servlet you make use of PrintWriter.

Refer its API here.

Thanks,
Ashwini Kashyap
 
kamal palia
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>");
out.println("</form>");

and it directly calls that jsp.
 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats great!!! You're welcome :)

Thanks,
Ashwini Kashyap
 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!