Exercise / display tree in JSP

Until recently, I though it was not possible to display a tree
with JSP pages unless using some "external" code [tag,js,etc.] for
generating the HTML.
So I propose you a little challenge:
- display a tree [for example a directory structure starting from a given directory]
- in a nested form
- with no library tags
- without direct use of "out"
- <%= ... %> only allowed to display file names
- with a single JSP

what you want ommit is all the advantage of the jsp:(()
without those, why people use jsp?My purpose is only to demonstrate that it is possible to display
a nested structure with "simplistic" JSP. So, will you take up the challenge ?

Similar Messages

  • Urgent : Trees in JSP

    hii guys
    i am very new to jsp..i want to display a employee hierachy structure( who reports to whom)..
    current i am using java swing tree and loading it in applet..but this is giving me problem because of the large size of driver file..
    i would like to know if i can embed swing tree or any other tree which jsp supports.i want to update the tree dynamically i.e when the user clicks on a employee i wnat to expand it to show who reports under him...
    plzzz reply very soon..thanks
    sairam

    JSP has no native support for displaying trees. Hence I have created a tag library to solve the problem
    http://www.jenkov.dk/projects/treetag/treetag.jsp
    Jakob Jenkov
    www.jenkov.dk

  • Display image in JSP Portlet

    I create a JSP portlet. But The portlet can't display image(gif file, jpg file). I have modified the provider.xml and the following line is added:
    <imageURL>URL_Path</imageURL>
    But, the image still cannot be displayed.
    How can I display image in JSP portlet?

    Leo Cheung,
    You could try the following :
    1. Add a virtual directory path Alias 'imgf' in the Apache configuration file httpd.conf to load the image file. Add the following line under the alias section :
    Alias /imgf/ "<your directory>\images/"
    2. Place your gif/jpg files (eg., work.gif) in the images directory.
    3. Use the IMG tag of HTML :
    <IMG src="/imgf/work.gif" border=0 width=80 height=80> in the JSP file at the location where you need to display the image.
    Hope this helps
    Pushkala

  • Unable to display tree view; Error when parsing an XML document (Premature end of file.)

    Hi folks,
    I am using a cascaded mapping in my OM. I have a graphical mapping followed by the Java mapping. It is a flat file to IDOC mapping. Everything works fine in Dev but when I transport the same objects to QA, the Operation mapping though it doesn't fail in ESR testing tool, gives the following message and there is no output generated for the same payload which is successfully tested in DEV. Please advise on what could be the possible reasons.
    Unable to display tree view; Error when parsing an XML document (Premature end of file.)

    kalyan,
    There seems to be an invalid xml payload which causes this error in ESR not generating the tree view. Please find the similar error screenshot and rectify the payload.
    Mutti

  • Junk characters like" � � "displayed in the jsp page please help.

    Hi,
    I am getting junk characters like � � displayed in the jsp page.
    In the JSP page i used javascript "& nbsp" for appending spaces to a string "CCR" to get "CCR " .
    Now the Resultant string "CCR " has three spaces appended to its right.
    This String is set in session in that JSP page.
    In the next JSP page i am getting that string from session.
    After getting the string the "substring" function is performed to get only the first 5 charcters of the string. Now the result is displayed as " CCR� � " with has last 2 characters as junk values � � insteed of displaying as "CCR ". Please help me in solving this issue.
    Please note that initially the sting "CCR" is got from the Oracle database in Solaris Machine.
    Regards,
    Vijay

    have you tried:
    strenuously inspecting the string that is coming from the db? do an actual loop over the string, character by character, dumping to System.out to make sure the characters are EXACT coming out of the db.
    note you have to append " " not just "& nbsp"
    post the code that is doing the output. the relevant bean code, the jsp, everything relevant - WITH COMMENTS discussing where things are happening.
    Also, is it "weird characters" in the browser only? have you done a view source on the actual html source that the browser is rendering (right click in IE and click view source). browsers can act odd if you don't feed then exactly what they want, and it looks like you're feeding it escaped characters that it is rendering as something else.

  • JavaMapping in PI 7.1 Error:Unable to display tree view; Error when parsing

    hi,
    i get by testing in PI 7.1 (operation mapping) this ERROR:
    "Unable to display tree view; Error when parsing an XML document (Content is not allowed in prolog.)"
    this is my java-programm-code:
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import com.sap.aii.mapping.api.StreamTransformation;
    import java.io.*;
    import java.util.Map;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    /*IMPORT statement imports the specified classes and its methods into the program */
    /Every Java mapping program must implement the interface StreamTransformation and its methods execute() and setParameter() and extend the class DefaultHandler./
    public class Mapping extends DefaultHandler implements StreamTransformation {
    Below is the declaration for all the variables we are going to use in the
    subsequent methods.
         private Map map;
         private OutputStream out;
         private boolean input1 = false;
         private boolean input2 = false;
         private int number1;
         private int number2;
         private int addvalue;
         private int mulvalue;
         private int subvalue;
         String lineEnd = System.getProperty("line.separator");
    setParamater() method is used to store the mapping object in the variable
    "map"
         public void setParameter(Map param) {
              map = param;
         public void execute(InputStream in, OutputStream out)
                   throws com.sap.aii.mapping.api.StreamTransformationException {
              DefaultHandler handler = this;
              SAXParserFactory factory = SAXParserFactory.newInstance();
              try {
                   SAXParser saxParser = factory.newSAXParser();
                   this.out = out;
                   saxParser.parse(in, handler);
              } catch (Throwable t) {
                   t.printStackTrace();
    As seen above execute() method has two parameters "in" of type
    InputStream and "out" of type OutputStream. First we get a new instance
    of SAXParserFactory and from this one we create a new Instance of
    SAXParser. To the Parse Method of SaxParser, we pass two parameters,
    inputstream "in" and the class variable "handler".
    Method "write" is a user defined method, which is used to write the
    string "s" to the outpurstream "out".
         private void write(String s) throws SAXException {
              try {
                   out.write(s.getBytes());
                   out.flush();
              } catch (IOException e) {
                   throw new SAXException("I/O error", e);
         public void startDocument() throws SAXException {
              write("");
              write(lineEnd);
              write("");
              write(lineEnd);
         public void endDocument() throws SAXException {
              write("");
              try {
                   out.flush();
              } catch (IOException e) {
                   throw new SAXException("I/O error", e);
         public void startElement(String namespaceURI, String sName, String qName,
                   Attributes attrs) throws SAXException {
              String eName = sName;
              if ("".equals(eName))
                   eName = qName;
              if (eName.equals("NUMBER1"))
                   input1 = true;
              if (eName.equals("NUMBER2"))
                   input2 = true;
         public void endElement(String namespaceURI, String sName, String qName)
                   throws SAXException {
              String eName = sName;
              if ("".equals(eName))
                   eName = qName;
              if (eName.equals("NUMBER1"))
                   input1 = false;
              if (eName.equals("NUMBER2"))
                   input2 = false;
         public void characters(char[] chars, int startIndex, int endIndex)
                   throws SAXException {
              String dataString = new String(chars, startIndex, endIndex).trim();
              if (input1) {
                   try {
                        number1 = Integer.parseInt(dataString);
                   } catch (NumberFormatException nfe) {
              if (input2) {
                   number2 = Integer.parseInt(dataString);
              if (input2 == true) {
                   addvalue = number1 + number2;
                   mulvalue = number1 * number2;
                   subvalue = number1 - number2;
                   write("" + addvalue + "");
                   write(lineEnd);
                   write("" + mulvalue + "");
                   write(lineEnd);
                   write("" + subvalue + "");
                   write(lineEnd);
    in developer studio 7.1 i dont get error.
    this happens by testing the mapping-programm in ESR.
    can somebody help me please?

    Make sure that the xml created out after the java mapping is a valid xml with only one root node.
    Regards,
    Prateek

  • Display tree in JTree

    Hi, I would like to ask you how can I display my Tree? in JTree?
    I create tree:
    Folder fol = new Folder(folderName, numFiles);
    DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(fol);
    ....But now I does not know how to display tree with folder names. When I use tree.setModel(...); it display object, but not folder names...
    And how can I use red font color for folder names with 0 files(numFiles = 0)?

    Hi, I would like to ask you how can I display my
    Tree? in JTree?
    I create tree:
    Folder fol = new Folder(folderName, numFiles);
    DefaultMutableTreeNode treeNode = new
    DefaultMutableTreeNode(fol);
    ....But now I does not know how to display tree with
    folder names. When I use tree.setModel(...); it
    display object, but not folder names...you need to walk through your tree and create a new DefaultMutableTreeNode for each of your nodes and add to its parent node of your JTree (remember there is a distinction between view and control). the user object of your DefaultMutable TreeNodes is the file/folder, which should be in its own class (see below) and overwrite toString() to return the name. then the JTree will show what you want.
    >
    And how can I use red font color for folder names
    with 0 files(numFiles = 0)?you need a tree cell renderer. it gets your file/folder object (see above) as a parameter. you can query it about the number of files and set the foreground/background accordingly.
    thomas

  • Display Tree structure using EVS or OVS

    Hi All,
        Here we have a requirement like display tree structure when I press F4. currently the sample application (using Object Value Selector or Extended Value Selector) is displaying the values in table, instead of table here we have to display it in tree.
       If it is not possible using either OVS or EVS please tell me what is the other way to solve the problem.
    Please give me any suggestion.
    Regards
    Suresh

    Suresh,
    You can emulate the behaviour by having a separate view for the tree structure.
    1.) Create a new view and put your tree structure UI + related logic in that view.
    2.) Create an input field and a linkToAction / button (with the text "Search".) aligned side by side.
    3.) On click of the search button, show the view containing tree as pop-up.
    You may develop upon this hint to meet your requirement.
    ~ Bala

  • Display tree node data in bold characters

    Hi,
    I have a requirement where I need to display tree nodes data in bold characters. If I click on a particular tree node, next time it should appear in normal font only which means that some task had done using that tree node. Is my question clear??
    Plz help me....
    thanks,
    ravindra.

    Hi Ravindra,
    I think it is possible, i have not done it but let me explain how we can do it.
    In <htmlb:treeNode> tag there is an attribute 'text' in
    which we specify title of that treeNode.
    Now you define a page attribute 'treeNodeTitle' type
    edpline and in onCreate assign it value <html><b>MyTreeNode</b></html>
    When you click on this node then you do event handling
    in onInputProcessing, there assign only 'MyTreeNode' to
    treeNodeTitle.
    sample code may look like this...
    <htmlb:treeNode
      id = 'treeNode1'
      text = '<%=treeNodeTitle %>' >
    </htmlb:treeNode>
    Page Attribute
    treeNodeTitle type edpline
    in onCreate
    treeNodeTitle = '<html><b>MyTreeNode</b></html>'
    in onInputProcessing
    in event-handling code for that treeNode write
    treeNodeTitle = 'MyTreeNode'
    I hope this will work.
    Regards,
    Narinder Hartala

  • Display Tree Structure in a List / Select Box

    I need info on the following
    1.display tree structure inside a select/combo/list box.
    2.Select a node element from the above tree structure.
    Thanks in advance

    Have you managed to do this?
    Faaiez

  • How to display photo in jsp through blob from oracle

    i am struggling here to retrieve an image which is stored in oracle-blob data type through jdbc-type-1.and i am unable to display that in jsp.i had a rich code library for this problem.but nothing gave me the exact solution.
    please give me exact the solution..
    pls ...

    What have you tried?
    What happened?

  • Display image on jsp page

    I have to display image on jsp page with some text output. This image is already saved at a location parallel to web-inf and is generated dynamically using a servlet. I have used img tag html to display the image. Other outputs are taking their values from database.
    First problem is that image will be taking time to display in comparision of other outouts from database. I have to refresh the page to get imageon my page.
    Second is that if I save image in a folder parallel to web-inf in my project then it will not be displaying the image.
    Can I use any jsp functionality to display image with other outputs from database. I have used "*include*". but it shows only that image and other outputs.

    Best way is to use a servlet for this.
    <img src="path/to/imageservlet?id=someidentifier">
    <!-- or -->
    <img src="path/to/imageservlet/someidentifier">In the servlet's doGet() just write code which gets an InputStream of the image (either directly generated, or just read from the local disk file system, if necessary with help of ServletContext#getRealPath(), or even from the DB by ResultSet#getBinaryStream()) and writes it to the OutputStream of the response. That's basically all. Don't forget to buffer the streams properly to speedup performance and to save memory.
    You can find here a basic example: [http://balusc.blogspot.com/2007/04/imageservlet.html].

  • How to display PDF in JSP using Iframe

    Hi All,
    I am using Struts 2. I am building my file in ActionClass with seperate Method like getGeneratedPDF() in which, I am setting header of response and writing into PDF.
    This method will be called from JSP by this way
    s:property value="getGeneratedPDF()" />
    But It displayed Junk Characters , and this PDF is not static (already Generated). It is generated and build on Fly.
    I have 2 questions 1 -- How to display PDF in JSP in proper way without Junk Character in it?
    questions 2 -- How to display it in Iframe?
    Please help me , If you know the solution.
    Thanks in Advance,
    Jimmy

    jamy_26 wrote:
    But It displayed Junk Characters , and this PDF is not static (already Generated). It is generated and build on Fly.A PDF file is a binary file, not a text file, and you're trying to display it as String. Of course you would get "junk characters". Have you ever tried opening a binary file (pdf, doc, jpg, xls, etc) using a text editor like Notepad?
    I have 2 questions 1 -- How to display PDF in JSP in proper way without Junk Character in it?Display it as binary stream, not as text stream. You can display it standalone, just let the link/form/addressbar URL point to some Servlet which writes the InputStream of the PDF file to the OutputStream of the response, along with a correct set of response headers (at least content-type, content-disposition and content-length), so that the browser can open it in the correct application (which is usually Acrobat Reader). If you want to embed the PDF file in a JSP, then one of the ways is indeed using the HTML <iframe> tag.
    questions 2 -- How to display it in Iframe? Just let the iframe URL point to the aforementioned Servlet.
    You can find here an example of a generic file servlet, you may find it useful to get the idea how to do it: [http://balusc.blogspot.com/2007/07/fileservlet.html].

  • Problem in Retrieve Image from DB and display in the JSP page

    Hi All,
    I did one JSP Program for retriveing image from DB and display in the JSP Page. But when i run this i m getting "String Value" output. Here i have given my Program and the output. Please any one help to this issue.
    Database Used : MS Access
    DSN Name : image
    Table Name: image
    Image Format: bmp
    Output : 1973956
    Sample Program:_
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import="java.io.*" %>
    <%
         try{
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection conn = DriverManager.getConnection("jdbc:odbc:image");
              Statement st = conn.createStatement();
              ResultSet rs = st.executeQuery("SELECT images FROM image");
              String imgLen="";
              if(rs.next()){
                   imgLen = rs.getString(1);
                   out.println(imgLen.length());
              if(rs.next()){
                   int len = imgLen.length();
                   byte [] rb = new byte[len];
                   InputStream readImg = rs.getBinaryStream(1);
                   int index=readImg.read(rb, 0, len);
                   System.out.println("index"+index);
                   st.close();
                   response.reset();
                   response.setContentType("image/jpg");
                   response.getOutputStream().write(rb,0,len);
                   response.getOutputStream().flush();
         }catch(Exception ee){
              out.println(ee);
    %>
    Thanks,
    Senthilkumar S

    vishruta wrote:
    <%
    %>Using scriptlets is asking for trouble. Java code belongs in Java classes. Use a Servlet.
                   out.println(imgLen.length());Your JSP was supposed to write an image to the output and you wrote some irrelevant strings to the output before? This will corrupt the image. It's like opening the image in a text editor and adding some characters before to it.
                   byte [] rb = new byte[len];Memory hogging. Don't do that.
              out.println(ee);You should be throwing exceptions and at least printing its trace, not sending its toString() to the output.
    You may find this article useful to get an idea how this kind of stuff ought to work: [http://balusc.blogspot.com/2007/04/imageservlet.html].

  • Graphical tree in JSP

    I wanna write a code that will allow users to make a tree structure at runtime, it must be a web based server site most preferably in JSP

    cotton.m,
    Unless you are planning to use an applet this won't be happening.Exactly and this is what happened to me when I tried to implement table tree in jsp and javascript, after several approach; it turn out the is no way of controlling the view; then I moved to build the Report based on applet
    You don't seem to be aware that JSP code executes on the server. And produces something like HTML. Which is then viewed in the browser.Yes and It is not easy to handle the event on the browser to the server; especially if you want to use one component from Struts or any rich client interface framwork, you will end up adding the whole libraries and different configurations etc.. so there is not light weight approach to extract what you need from these frame work (ZK, Struts, Myfaces etc..)
    Regards,
    Alan Mehio
    London,UK

Maybe you are looking for

  • Place command not appearing in file menu

    I click file and do not see the Place Command so I can insert picture. Where else could it be?

  • How do I enable my iPhone4 once it has been disabled

    I recently changed my iPhone password to get into the phone. I am now unable to get into my phone. My phone is disabled so how can I enable my phone without my password?

  • Resolution/Aspect Ratio of .SWF

    hi all, i just need to know how the aspect ratio of swf be same when we play the swf on LCD,Plasma TVs. As currently the .swf changes if we check it on the TV screen. Any help on this will be highly appriciated. thanks and regards nik

  • What's with the prices?

    Anyone know why the exact same movie cost $2.99 to rent from the iTunes store on my Mac (which I can then stream to my ATV2) and $3.99 to rent on the ATV? What's so different that it needs to cost an extra dollar just because I hit the rent button on

  • Bugs in GPU renders in Premiere CC 2014

    I have two UltraKey effects applied to a clip (one of them with a mask for special cleanup on a person's hair). With GPU turned on, in a rendered video, the person's hair has a flickering halo, like the second UltraKey is alternating between being on