aspose file tools*
The moose likes JSP and the fly likes need to get response xml string back from servlet to jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "need to get response xml string back from servlet to jsp page" Watch "need to get response xml string back from servlet to jsp page" New topic
Author

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

Ray Smilgius
Ranch Hand

Joined: Jan 29, 2001
Posts: 120
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).]


SCJO, SCJD, SCWCD, I-Net+, A+, Network+, MCSD, MCDBA, MCP, MCT
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
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

Joined: Jan 29, 2001
Posts: 120
could you show me a snippet of code to display your idea.
setAttribute("theDOM", theDOM

Thanks in advance
Ray Smilgius
Ray Smilgius
Ranch Hand

Joined: Jan 29, 2001
Posts: 120
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).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need to get response xml string back from servlet to jsp page