• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

need to get response xml string back from servlet to jsp page

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am posting from a login.jsp that calls a servlet and I need to get the response of that servlet and send it to another jsp page called template.jsp
here is the code in my servlet
this is in the doPost() method::::
response.sendRedirect("http://" + req.getHeader("host") + "/" + "star/template.jsp");

here is code::::using tomcat
<%@page import="javax.xml.parsers.DocumentBuilderFactory,java.net.*,java.io.*,javax.xml.parsers.DocumentBuilder,org.w3c.dom.*" %>

<html>
<head>
<title>My first template</title>
</head>
<body>

<%
InputStream in = request.getInputStream();//trying to get the inputstream back from servlet and parse it, right now I have this path hardcoded in the parse function and it works but how can I grab this string from the servlet. and pass it directly into the parse and build my DOM??
out.println(in);
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.parse("http://rsmilgius:8080/star/employee.xml");//need to use InputStream from servlet any ideas???
NodeList idNl=doc.getElementsByTagName("id");
NodeList nameNl=doc.getElementsByTagName("name");
%>
The Data Response from IDS<p/>
<%
for(int i=0;i<nameNl.getLength();i++)
{
String idname=idNl.item(i).getNodeName();
String idvalue=idNl.item(i).getFirstChild().getNodeValue();
String name=nameNl.item(i).getNodeName();
String nvalue=nameNl.item(i).getFirstChild().getNodeValue();
out.println(idname+"=>"+idvalue+" "+name+"=>"+nvalue+"<BR>");
}
%>
</body>
</html>
Thanks in advance Ray Smilgius

[This message has been edited by Ray Smilgius (edited November 12, 2001).]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of all that clumsy JSP syntax, parse the stream in the servlet and attach the resulting document to the session or to the request with setAttribute("theDOM", theDOM )
 
Ray Smilgius
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could you show me a snippet of code to display your idea.
setAttribute("theDOM", theDOM

Thanks in advance
Ray Smilgius
 
Ray Smilgius
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String theURL = "http://your_server.com/yourpage.jsp?"+ "Parameter1=" +doc;
response.sendRedirect(theURL);
Then on the template.jsp
<!%Doc myDom; %>
myDom = request.getParameter("doc");
NodeList idNl=myDom.getElementsByTagName("id");
NodeList nameNl=myDom.getElementsByTagName("name");
Bill This is what I am thinking am I correct???
Thanks in Advance
Ray Smilgius


[This message has been edited by Ray Smilgius (edited November 12, 2001).]
 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic