Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet XML response correct in broser but incorrect in Java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mamba
XML response correct in broser but incorrect in Java
1 Answer(s)      2 years and 4 months ago
Posted in : JSP-Servlet


Firs of all I want to say that I was able to read XML response from URL. Thank you for this and many other helps. I read and printed the response (code below) but the result is not correct.

In browser shows me (correct):

<ENELIT>
<GESI>
<RI>
<NR id="008201dfa306f4a2" tu="N" nr="0412395504" ut="" cp="" dp="" tm="" ca="" da="" rt="" cc="4"/>
</RI>
</GESI>
</ENELIT>

And in Java it prints this (incorrect):

<html>
  <head>
    <link rel=stylesheet href="/psiche/styles/IEStyle.css" type="text/css">
  </head>
  <body>

    <SCRIPT FOR=window EVENT=onload LANGUAGE="JAVAScript">
      if (top.areaApplication != undefined)
      {
        alert("Sessione utente scaduta. Effettuare il logon");
        top.areaApplication.location = "/gesi/online/root/login.htm";
      } 
    </SCRIPT>
    <h2>Sessione scaduta, Effettuare il logon.</h2> 
  </body>   
</html>

How can I get the correct result? Thank you!

My code for getting and printing the response: Example 1:

URL url = new URL("http://gesi-ro-test.banat.enelro:8010/dynamic/gesi/ri/elab/phonerequest/wind.serid=008201dfa306f4a2&nr=06648624&is=2011/04/20%2013:03:03.296&rt=RE/");
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));

String inputLine;
while ((inputLine = in.readLine()) != null)
      System.out.println(inputLine);
in.close();

Example 2:

URL url = new URL("http://gesi-ro-test.banat.enelro:8010/dynamic/gesi/ri/elab/phonerequest/wind.ser?id=008201dfa306f4a2&nr=06648624&is=2011/04/20%2013:03:03.296&rt=RE");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
InputStream stream = connection.getInputStream();

BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
StringBuilder sb = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null)
{
    sb.append(line).append("\n");
}
stream.close();
System.out.println(sb.toString());

Advertisement
View Answers

August 22, 2012 at 4:48 PM


I just saw your thread and analysed your problem you are facing. I suggest that your browser is cooperating with the server in maintaining a session, most likely by receiving and sending a cookie. Your Java code should do the same thing. So first it should go to the login page with the right parameters, and then it should receive a cookie along with the response, and then it should go to the data page, sending the cookie along with the data.



Related Tutorials/Questions & Answers:
XML response correct in broser but incorrect in Java
XML response correct in broser but incorrect in Java  Firs of all I want to say that I was able to read XML response from URL. Thank you...;/ENELIT> And in Java it prints this (incorrect): <html> <head>
Identify correct and incorrect statements or examples about EJB programming restrictions.
Identify correct and incorrect statements or examples about EJB... Overview Next     Identify correct and incorrect statements... rules of the Java programming language make unavailable. The enterprise bean
Advertisements
Identify correct and incorrect statements or examples about the purpose and use of EJB QL.
Identify correct and incorrect statements or examples about...;Next    Identify correct and incorrect statements...;Home Identify correct and incorrect conditional expressions, BETWEEN
Identify correct and incorrect statements or examples about the client view of an entity bean's local component interface (EJBLocalObject).
Identify correct and incorrect statements or examples about...;   Identify correct and incorrect statements or examples about the client... correct and incorrect statements or examples about the client view
Identify correct and incorrect statements or examples about the client view of a entity bean's remote component interface (EJBObject).
Identify correct and incorrect statements or examples about...;   Identify correct and incorrect statements or examples about....     Prev Up NextIdentify correct and incorrect
Identify correct and incorrect conditional expressions, BETWEEN expressions, IN expressions, LIKE expressions, and comparison expressions.
Identify correct and incorrect conditional expressions...; Identify correct and incorrect conditional expressions...;   Prev Up NextIdentify correct and incorrect statements
Identify correct and incorrect statements or examples about the client's view of exceptions received from an enterprise bean invocation.
Identify correct and incorrect statements or examples about...; Identify correct and incorrect statements or examples about the client's view... interfaces are both Java RMI interfaces, and therefore the throws clauses
Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces.
Identify correct and incorrect statements or examples about the client view of a session bean's local and remote component interfaces...;   Identify correct and incorrect statements or examples about
Identify correct and incorrect statements or examples about the rules and semantics for relationship assignment and relationship updating in a CMP bean.
Identify correct and incorrect statements or examples about...; Prev Up NextIdentify correct and incorrect statements or examples... for Container-Managed Persistence (CMP) Next     Identify correct
Given a security-related deployment descriptor tag, identify correct and incorrect statements and code related to that tag.
correct and incorrect statements and code related to that tag. Prev ...; Given a security-related deployment descriptor tag, identify correct and incorrect statements and code related to that tag
Identify correct and incorrect statements or examples about an entity bean's primary key and object identity.
Identify correct and incorrect statements or examples about.... Entity Beans Next    Identify correct and incorrect statements or examples about an entity bean's primary key and object
Free Java Is it correct?
Free Java Is it correct?  Hi, Is Java free? If yes then where I can download? Thanks   Hi, You can download it from http://www.oracle.com/technetwork/java/javase/downloads/index.html Thanks
Identify correct and incorrect statements about the Application Assembler's responsibilities, including the use of deployment descriptor elements related to transactions and the identifica
Identify correct and incorrect statements about the Application Assembler's responsibilities, including the use of deployment descriptor elements...; Identify correct and incorrect statements about the Application Assembler's
Correct errors - Java Beginners
Correct errors  Identify and correct the errors in the following program: public java Method { public static method1(int n, m) { n += m; xMethod(3. 4); } public static int xMethod(int n) { if (n > 0) return 1
Identify correct and incorrect statements or examples about application exceptions and system exceptions in entity beans, session beans, and message-driven beans.
Identify correct and incorrect statements or examples about application exceptions and system exceptions in entity beans, session beans...;Exceptions Next    Identify correct and incorrect statements
Produces XML file but format not correct for storing data using JSP and XML
Produces XML file but format not correct for storing data using JSP and XML  hii I have created a project using JSP and XML as database to store data entered by user in XML file ,It stores data entered in XML file
Identify correct and incorrect statements or examples about persistent relationships, remove protocols, and about the abstract schema type of a CMP entity bean.
Identify correct and incorrect statements or examples about...; Identify correct and incorrect statements or examples about persistent... for Container-Managed Persistence (CMP) Home Identify correct and incorrect
Identify correct and incorrect statements about the purpose and use of the deployment descriptor elements for environment entries, EJB references, and resource manager connection factory r
Identify correct and incorrect statements about the purpose and use... correct and incorrect statements about the purpose and use of the deployment... whether a given code listing is appropriate and correct with respect
Java Servlet : Http Response Headers
Java Servlet : Http Response Headers In this tutorial, you will learn how to Http Response Headers works in java servlet. Http Response Headers : Web server sends response with one or more response headers including the document
How we can integrate ASP .net website to payment gateway using SOAP xml request and response using wsdl.
gateway provider provide us SOAP Xml request and SOAP xml response format along...How we can integrate ASP .net website to payment gateway using SOAP xml request and response using wsdl.  We have a e-commerce website in ASP.net, c
How do I write a correct micro-benchmark in Java?
How do I write a correct micro-benchmark in Java?  How do I write a correct micro-benchmark in Java
java and xml - XML
java and xml  Hi Deepak, I want learn xml and java(applications). Which editor is best usefull(trial--version) in my applications...; Hi friend, http://www.roseindia.net/xml/dom/ Thanks
Java + XML - XML
Java + XML  1) I have some XML files, read one xml... java...the attribute value..not sure now how to read the xml file passing..." pointing to a hello xml file ..read that file and get the value of the parent
Java-XML-DOM - XML
Java-XML-DOM  Hi! I need some help. I have to make java program that loads an xml file and from it builds DOM(later i will have to work with it - like using xpath in java find some value and replace it...). Since i'm new to java
java and xml - XML
java and xml   test_final_1 2009-025T13:23:45 B2B I want to validate each tag.. and i don't have any xsd.. kindly help me to solve...://www.roseindia.net/xml/dom/DOMValidateDTD.shtml Thanks
XML with JAVA - XML
document and the processing in JAVA program . Find the time for each XML element...XML with JAVA  Hi.. This is Priya here. Thanks for responding me. I have a query. "Write program in java to evaluate the time to access
java and xml problem - XML
java and xml problem  hi, i need to write a java program that generates an xml file as follows: aaa vvv --------- i have witten a program in java, but im
java with xml
java with xml  Hi i am reading xml data with sax parser in java. ok its fine. But in future xsd and xml will change. now my question is if xsd and XML will change my java progrm will not change. is it possible ? Thanks
java with xml
java with xml  Hi i am reading xml data with sax parser in java. ok its fine. But in future xsd and xml will change. now my question is if xsd and XML will change my java progrm will not change. is it possible ? Thanks
XMl and Java web services
XMl and Java web services  I want to do a project on java web services and XML. I wanted to ask, how the data entered by user through the HTML file... and JDBC the response can be sent back to the client? Also, how the XML file can
XML in java - XML
XML in java  Write a program using SAX that will count the number of occurrences of each element type in an XML document and display them...://www.roseindia.net/xml/sax/SAXElementCount.shtml Hope that it will be helpful
Advertisements
 

 

 

DMCA.com