want my jsp to use object from a class which i initialized from servle

import="org.jdom.*,
org.jdom.input.*,
org.jdom.output.*"

public void show(){
//show all file contents in RssView.jsp
try{
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File("c:\rsshandler.xml"));
XMLOutputter fmt = new XMLOutputter();
fmt.output(doc, System.out);

} catch (Exception e) {
e.printStackTrace();
}
}

In My RssVIew.jsp if i just get doc(Document) object i can use rest of the methods from jdom to display contents of my xml rss file in jsp which is my ultimate target to achieve.


what i have written for now is in my jsp is this please suggest me something better then this.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<%@ taglib prefix="caui" uri="http://www.ca.com/ca-corpui/r2/jsptags" %>

<%@ page language="java"
import="java.io.*"
import="java.util.*"
import="org.jdom.*,
org.jdom.input.*,
org.jdom.output.*"
import="com.ca.corpui.JSPTags.*,
com.ca.corpui.model.*"
import="src.RssFileHandler,src.RssActionServlet"
%>
<%
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File("c:\rsshandler.xml"));
XMLOutputter fmt = new XMLOutputter();
fmt.output(doc, System.out);
// Get the root element
Element root = doc.getRootElement();

// Print servlet information
List servlets = root.getChildren("channel");
out.println("This WAR has "+ servlets.size() +" registered servlets:");
Iterator i = servlets.iterator();
while (i.hasNext()) {
Element servlet = (Element) i.next();
out.print(" " + servlet.getChild("channeltitle")
.getText() +
" for " + servlet.getChild("channellink")
.getText());
List initParams = servlet.getChildren("channeldescription");
out.println(" (it has " + initParams.size() + " init params)");
}

} catch (Exception e) {
e.printStackTrace();
}
%>



thanks
Vijendra

Comments

  • : import="org.jdom.*,
    : org.jdom.input.*,
    : org.jdom.output.*"
    :
    : public void show(){
    : //show all file contents in RssView.jsp
    : try{
    : SAXBuilder builder = new SAXBuilder();
    : Document doc = builder.build(new File("c:\rsshandler.xml"));
    : XMLOutputter fmt = new XMLOutputter();
    : fmt.output(doc, System.out);
    :
    : } catch (Exception e) {
    : e.printStackTrace();
    : }
    : }
    :
    : In My RssVIew.jsp if i just get doc(Document) object i can use rest of the methods from jdom to display contents of my xml rss file in jsp which is my ultimate target to achieve.
    :
    :
    : what i have written for now is in my jsp is this please suggest me something better then this.
    :
    : <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
    : <%@ taglib prefix="caui" uri="http://www.ca.com/ca-corpui/r2/jsptags" %>
    :
    : <%@ page language="java"
    : import="java.io.*"
    : import="java.util.*"
    : import="org.jdom.*,
    : org.jdom.input.*,
    : org.jdom.output.*"
    : import="com.ca.corpui.JSPTags.*,
    : com.ca.corpui.model.*"
    : import="src.RssFileHandler,src.RssActionServlet"
    : %>
    : <%
    : try {
    : SAXBuilder builder = new SAXBuilder();
    : Document doc = builder.build(new File("c:\rsshandler.xml"));
    : XMLOutputter fmt = new XMLOutputter();
    : fmt.output(doc, System.out);
    : // Get the root element
    : Element root = doc.getRootElement();
    :
    : // Print servlet information
    : List servlets = root.getChildren("channel");
    : out.println("This WAR has "+ servlets.size() +" registered servlets:");
    : Iterator i = servlets.iterator();
    : while (i.hasNext()) {
    : Element servlet = (Element) i.next();
    : out.print(" " + servlet.getChild("channeltitle")
    : .getText() +
    : " for " + servlet.getChild("channellink")
    : .getText());
    : List initParams = servlet.getChildren("channeldescription");
    : out.println(" (it has " + initParams.size() + " init params)");
    : }
    :
    : } catch (Exception e) {
    : e.printStackTrace();
    : }
    : %>
    :
    :
    :
    : thanks
    : Vijendra
    :


    Use Request.getParameter() and Request.setParameter() functions. Its easy this way. Try it out.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion