• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

trouble passing info from servlet to jsp

Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see the code and comments below for my issue and problem
<%@page import="javax.xml.parsers.DocumentBuilderFactory,java.net.*,java.io.*,javax.xml.parsers.DocumentBuilder,org.w3c.dom.*" %>
<%!Document myDom;%> is this correct ??? if I call it the myDom
<title>My first template</title>

<--comment out --DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance(); //dont need
<--comment out --DocumentBuilder db=dbf.newDocumentBuilder(); //dont need
<--comment out --Document doc=db.parse("http://rsmilgius/FortKnox/employee.xml"); //dont need
//how do I retrieve the Document from the servlet and declare it to doc so I can continue from here ???
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.print("Name of insured person (" + nvalue + ")" + "<br>");


/////the servlet code /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class pleasework extends HttpServlet {

URL url;
URLConnection urlConn;
DataOutputStream printout;
BufferedReader input;

public void init() throws ServletException {

System.out.println("TestServlet : init");
public void destroy() {
System.out.println("TestServlet : destroy");

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {

String user = req.getParameter("username");
String password = req.getParameter("password");

PrintWriter out = res.getWriter();

url = new URL ("http://ssteward:5001");
// URL connection channel.
urlConn = url.openConnection();
// Let the run-time system (RTS) know that we want input.
urlConn.setDoInput (true);
// Let the RTS know that we want to do output.
urlConn.setDoOutput (true);
// No caching, we want the real thing.
urlConn.setUseCaches (false);
// Specify the content type.
urlConn.setRequestProperty("Content-Type", "application/InScope");

// Send POST output.
printout = new DataOutputStream (urlConn.getOutputStream ());

//send the content to the server.

String content = "<?xml version=\"1.0\"?><employees><employee><user>" + user + "</user><password>" + password + "</password></employee></employees>";
//send contents to remote server
printout.writeBytes (content);
printout.flush ();
printout.close ();

// Get response data and put it into a DOM and parse it....

InputStream in = urlConn.getInputStream();

DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();

DocumentBuilder db=dbf.newDocumentBuilder();

Document doc=db.parse(in);

///////////////////////this is where I am baffled I need to attach the Document doc and send it on to template.jsp

//setAttribute(Dom,doc); ???

//this line of code works find below and template.jsp is displayed but need to attach Document
// and foward it to template.jsp where I can process it. Also, I need to also know how to retreive the doc in
//the template.jsp and then I am on my way....


// in.close();

catch (IOException ioe)

catch (SAXException e)

catch (ParserConfigurationException ess)


Thanks in advance
ray smilgius.

Sun Certified Java Programmer
Sun Certified Java Developer
I-Net Certified
A+ Certified
Network+ Certified
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your servlet, do the following
req.setAttribute("Dom", dom);
Then in your JSP you could use scriptlet like
<% Dom dom = (Dom) request.getAttribute("dom")%>
or you could use the use bean tag as follows
<jsp:useBean id="dom" class="Dom" scope="request"/>
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic