Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Out.println not able to write content to browser

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi team,

I am very surprised why out.println does not bale to write our HTML content to the browser.
Currently, I am having a situation where I post my request to servlet and servlet did some DB operation and some operation then it creates one HTML form to redirect customer to show the result but it is sometimes working and sometimes not... I tried so many times but it shows HTML content in log file but my final out.pritnln not able to redirect content on browser...

I am putting my sample HTML which I found from logs and my Printwriter out logic.
Below my HTML content...

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><title>CCAvenue-Transaction Page</title>< language='java'>window.history.forward(); function noBack() { window.history.forward(); } function Me(){ document.getElementById('submit').style.visibility='hidden';document.getElementById('submit').click(); }</></head><body style='margin:0px;' onLoad='noBack();Me();'><form name='MalltoEpay' method='post' action='https://secure.ccavenue.com/transaction.do?command=retryTransaction'/><input type='hidden' name='tracking_id' value='109892936454'><input type='hidden' name='page_type' value='TransactionRetry'><input type='hidden' name='tracking_id' value=''><input type='' id='submit' value='Continue' style='display:none;'></form></body></html>

The form is proper I verified and below code using to put my above HTML content to post on browser(Sometimes same code working and some times not)

pResponse.setContentType("text/html");
PrintWriter out = pResponse.getWriter();
out.print(vMBean.$_returnText);
out.flush();
out.close();

Please suggest and help....
 
Marshal
Posts: 3145
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Below my HTML content...

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><title>CCAvenue-Transaction Page</title>< language='java'>window.history.forward(); function noBack() { window.history.forward(); } function Me(){ document.getElementById('submit').style.visibility='hidden';document.getElementById('submit').click(); }</></head><body style='margin:0px;' onLoad='noBack();Me();'><form name='MalltoEpay' method='post' action='https://secure.ccavenue.com/transaction.do?command=retryTransaction'/><input type='hidden' name='tracking_id' value='109892936454'><input type='hidden' name='page_type' value='TransactionRetry'><input type='hidden' name='tracking_id' value=''><input type='' id='submit' value='Continue' style='display:none;'></form></body></html>

The form is proper I verified and below code using to put my above HTML content to post on browser(Sometimes same code working and some times not)


You need to look at the generated HTML and how you verified it - there appears to have many errors.

A few examples:
   < language='java'>window.history.forward(); ... </>
       - the opening and closing tags are missing an element name
       - if this is meant to be a <script> tag, do you really mean to tell the browser that the scripting language is java?

   <form name='MalltoEpay' method='post' action='https://secure.ccavenue.com/transaction.do?command=retryTransaction'/>
       - this is self-closing tag -- you are opening and closing the form element in the same tag, so any subsequent form-related elements will not be part of the form

   <input type='' id='submit' value='Continue' style='display:none;'>
       - the type attribute cannot be specified as empty

Also, what is the purpose of the page?  It looks like you are trying to stealthily have the browser submit a form without the user's knowledge - seems like a questionable thing to be doing.



 
Dheeraj Kumar Gupta
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply here...
Please find the below HTML that is being actually used to redirect HTML.

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml'><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8' /><title>CCAvenue-Transaction Page</title><script language='javascript'>window.history.forward(); function noBack() { window.history.forward(); } function SubmitMe(){ document.getElementById('submit').style.visibility='hidden';document.getElementById('submit').click(); }</script></head><body style='margin:0px;' onLoad='noBack();SubmitMe();'><form name='MalltoEpay' method='post' action='https://qasecure.ccavenue.com/transaction.do?command=retryTransaction'/><input type='hidden' name='tracking_id' value='209000766407'><input type='hidden' name='page_type' value='TransactionRetry'><input type='hidden' name='tracking_id' value=''><input type='submit' id='submit' value='Continue' style='display:none;'></form></body></html>

and as you raised the concern here the page in which we are using just intermediate page to show the processing things and if completed then above HTML will be actually showing the result of the page as "Success/Failure".
 
salvin francis
Saloon Keeper
Posts: 2620
128
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This statement is incorrect: "Out.println not able to write content to browser".
The PrintWriter you have does not write anything to the browser at all, all this is done on the webserver end. The data written to to output stream is sent to the client (browser).

Next, if you want to do a redirect, you dont need to have any html content at all. Simple call sendRedirect() on the HttpServletResponse.


 
Ron McLeod
Marshal
Posts: 3145
466
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Technical Ccav wrote:Please find the below HTML that is being actually used to redirect HTML.


After fixing your display name, try using an online validator such as https://validator.w3.org/ or https://www.freeformatter.com/html-validator.html to highlight the errors in your HTML document.
 
Dheeraj Kumar Gupta
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply,
If this is not the case of then how do we post dynamic Html through servlet to show end customer final success/failure result?

Please suggest..
 
salvin francis
Saloon Keeper
Posts: 2620
128
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the goal of the process is to do a redirect, then I suggest not having a success page in the first page. The user submits a request, the server does the db work and when done, does a redirect. It's as simple as that.
If there is a failure, then the server can choose to not do a redirect and return an error page instead.

On the other hand, showing the user a temporary success page that automatically does a javascript based redirects will have ton of issues:
  • User can simply close the browser window !!
  • User can press the back/cancel button
  • Javascript can be disabled on the user's browser
  • Network issues

  • PS: I agree with Ron, please change your display name as it does not follow our coderanch policies
     
      Bookmark Topic Watch Topic
    • New Topic