File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes writing HTML in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "writing HTML in servlet" Watch "writing HTML in servlet" New topic
Author

writing HTML in servlet

kamal palia
Greenhorn

Joined: Jul 20, 2012
Posts: 17
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35223
    
    7
What do you mean by "call JSP page"? The servlet just writes some text, it doesn't call (or forward to) anything.


Android appsImageJ pluginsJava web charts
Ashwini Kashyap
Ranch Hand

Joined: Aug 30, 2012
Posts: 61
For writing HTML in the servlet you make use of PrintWriter.

Refer its API here.

Thanks,
Ashwini Kashyap
kamal palia
Greenhorn

Joined: Jul 20, 2012
Posts: 17
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

Joined: Aug 30, 2012
Posts: 61
Thats great!!! You're welcome :)

Thanks,
Ashwini Kashyap
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35223
    
    7
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing HTML in servlet
 
Similar Threads
reading returned datas from the url
problem with request forward
How do you pass a string from servlet to jsp if jsp is on another server?
Autologin a website
Passing huge string to JSP..