tags:

views:

795

answers:

2

Hi guys.

I want to setup a JSP page to:

Note: I tried get "XML return result" from DDR server with javascript using ajax like the following code (like AJAX code). It done well :

 /**Send request*/
  http_request.onreadystatechange = alertContents;
  http_request.open('GET', url + parameters, true);
  http_request.send(null);
  .....
 /**get response from server*/
  return http_request.responseText;

But now I do not want to use Javascript, only want do by JSP.

How can I do with JSP?

Thank you!!!

+2  A: 

JSP is not really appropriate for this; servlet would probably be better. If you must do it in JSP you'll have to do it in the java snippet:

<%

 URL url = new URL("http://ddr.mobileok.kr/profile/DeviceProfile.do?mn=SCH-W420");
 HttpURLConnection connection = (HttpURLConnection) url.openConnection();
 connection.setRequestMethod("GET");
 connection.connect();
 InputStream stream = connection.getInputStream();
 // read input stream directly or via DOM or via SAX or whatever
%>
ChssPly76
+1 for saying that JSP is the wrong technology for this.
Stephen C
Thank you. It do useful for me. And please help me more.I want to convert that XML to JSON (do in java). How can I do?
haicnpmk44
You can write an XSLT stylesheet to do that. If you want to translate an entire XML "as is", there are already XSLT templates that would do it for you. Take a look at http://code.google.com/p/xml2json-xslt/, for example or http://www.google.com/search?q=xml+to+json+xslt for more options. If you need to pick and choose what nodes to map you'll have to write a custom stylesheet yourself.
ChssPly76
+1  A: 

Depending on what you want to do with the output you could just use a jsp include tag. These can be used to include any kind of page...

<jsp:include page="http://ddr.mobileok.kr/profile/DeviceProfile.do"&gt;    
   <jsp:param name="mn" value="SCH-W420" /> 
</jsp:include>

But I'll second the thought that this is the wrong way to do it.

Instead take the java code given in the other answer use it in a servlet (or any type of controller) parse the xml and then return it to the view layer.

If you want to convert this xml to json try the strangely named badgerfish -

http://sujitpal.blogspot.com/2007/10/converting-xml-to-badgerfish-json.html

Pablojim
Thank you. I want to convert that XML to JSON (do in java). Can I you help me!
haicnpmk44
see updated answer
Pablojim