From HTML string to HtmlDocument?

I have a String consists of a HTML string e.g. <br>Hello</br>
How to convert it into a javax.swing.text.html.HtmlDocument?

You can't convert any String directly to HTMLDocument !
HTMLDocument is a back-end of any HTML editor (eg.,JTextPane / JEditorPane).
If you want to have an HTMLDocument that represent your string "<br>Hello</br>" ,then do one thing. (Your HTML string is still invalid ,cos there is no such TAG called </br>)
JTextPane text=new JTextPane();
text.setContentType("text/html");
text.setText(yourHTMLString);
HTMLDocument doc= (HTMLDocument)text.getDocument();

Similar Messages

  • How to REMOVE [b] H1 Tag[/b] from HTML without changing other Tags?

    Hi there!
    I'm searching for a method to remove Tags from HTML (using HTMLEditorKit, HTMLDocument ...).
    My current code is as follows:
    // first get the whole paragraph
       int iCaretPos = tpMyTextPane.getCaretPosition();
       Object oAttrib;
       HTMLDocument.BlockElement oElem = (HTMLDocument.BlockElement)oMyDocument.getParagraphElement(iCaretPos);
       AttributeSet oAttribs;
       SimpleAttributeSet oNewAttribs;
       int iParaStart = oElem.getStartOffset();
       int iParaEnd = oElem.getEndOffset();
       tpMyTextPane.select(iParaStart, iParaEnd);
       // the following only fetches the Tags that are valid for the whole paragraph!!!!!
       oAttribs = tpMyTextPane.getCharacterAttributes();
       oNewAttribs = new SimpleAttributeSet(oAttribs);
       if(iParaEnd - iParaStart > 0)
          // now analyse the attributes (remove all paragraph-tags)
          for(int iIndex = 0; iIndex < oaOurFormatTags.length; iIndex++)
             oNewAttribs.removeAttribute(oaOurFormatTags[iIndex]);
          if(iParaEnd - iParaStart > 0)
             oMyDocument.setCharacterAttributes(iParaStart, iParaEnd - iParaStart, oNewAttribs, true);
             tpMyTextPane.setCaretPosition(iCaretPos);
          tpMyTextPane.requestFocus();
          tpMyTextPane.repaint();
       }This code works for me, but all Tags of the selected paragraph are removed. That means:
    <P><H1>This is a <B>test</B> text<H2></P>
    will be converted to:
    <P>This is a test text</P>
    but I want it to be converted to:
    <P>This is a <B>test</B> text</P>
    Is there any other method to remove specific Tags (<H1>, ... <H6>) without touching other tags????

    In February I wrote a feature request about this. Today it has been accepted to the bug database. Please make your vote:
    http://developer.java.sun.com/developer/bugParade/bugs/4760082.html

  • How to extract an element value from a String of HTML

    I have a web service that returns a fragment of HTML that contains a number in a table. The return parameter type is a string. I need to get this number and use it in a BPEL while loop, as the condition for the loop (while the number > 0).
    I have tried using the function bpws:getVariableData() but the BPEL PM faults and says: XPath expression failed to execute. Error while processing xpath expression. I think this is because I am trying to apply an XPath expression over a String variable.
    The return value from my web service looks like this:
    <whileConditionResultSet>
    <part xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" name="response">
    <ns1:string_Response xmlns:ns1="http://systinet.com/xsd/SchemaTypes/"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="d:string">
         <p>SQL Query: select count(*) from delta_manages</p>
         <p><table border='1'>
              <tr> <th bgcolor='#C0C0C0'>COUNT(*)</th></tr>
              <tr> <td>28</td></tr>
              </table>
         </p></ns1:string_Response>
    </part>
    </whileConditionResultSet>
    How do I get the value from the HTML table into a BPEL variable?

    the doSqlService() which executes an arbitrary SQL statement, returns a string of HTML like this:
    <doSqlServiceResponse>
    <part xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" name="response">
    <ns1:string_Response xmlns:ns1="http://systinet.com/xsd/SchemaTypes/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="d:string"><p>SQL Query: select count(*) from delta_manages</p> <p><table border='1'> <tr> <th bgcolor='#C0C0C0'>COUNT(*)</th></tr> <tr> <td>14</td></tr> </table></p></ns1:string_Response>
    </part>
    I then copy the result to the whileResultString variable
    <variable name="whileResultString" type="xsd:string"/>
    <copy>
                                       <from variable="doSqlServiceResponse" part="response" query="/ns1:string_Response">
                                       </from>
                                       <to variable="whileResultString"/>
                                  </copy>
    I realise too, a root element will be needed. This is not a mission critical problem as we could change the web service at the other end. It was originally designed for a client to display the results rather than use them within a business process. Anyway, I'm just interested to know if I can create a node from this string data in BPEL.
    Ross.

  • Remove HTML tags from a string

    I have a string that contains a couple of HTML or XHTML tag, for example
    lv_my_string = '<p style="something">Hello <strong>World</strong>!</p>'.
    For a special use case, I want to remove all HTML from that string and process only the plain text
    lv_my_new_string = 'Hello World!'.
    Is there any method, function module, XSLT or anything else for that already?

    Hi Daniel,
    I tried using the FM (SWA_STRING_REMOVE_SUBSTRING) but I guess it is expecting a particular pattern which is not so apparent in your case. Iu2019ve written a small piece of code which you can try using in a FM or a PERFORM and that should do the trick. Please let me know if you have any questions.
    PARAMETER: P_LINE(100).
    TYPES: BEGIN OF TY_LINE,
             LINE(100),
           END OF TY_LINE.
    DATA: T_LINE TYPE STANDARD TABLE OF TY_LINE,
          WA_LINE LIKE LINE OF T_LINE.
    DATA: W_LINE(100),
          W_LEN(100),
          W_COUNT TYPE I,
          W_FLAG,
          W_FLAG1,
          W_I TYPE I.
    W_COUNT = STRLEN( P_LINE ).
    DO W_COUNT TIMES.
      IF P_LINE+W_I(1) = '<'.
        W_FLAG = 1.
        W_I = W_I + 1.
        IF NOT WA_LINE-LINE IS INITIAL.
          APPEND WA_LINE-LINE TO T_LINE.
          CLEAR WA_LINE.
        ENDIF.
        CONTINUE.
      ELSEIF P_LINE+W_I(1) = '>'.
        W_FLAG = 0.
        W_I = W_I + 1.
        CONTINUE.
      ENDIF.
      IF W_FLAG = 1.
        W_I = W_I + 1.
        CONTINUE.
      ELSE.
        CONCATENATE WA_LINE-LINE P_LINE+W_I(1) INTO WA_LINE-LINE.
        W_I = W_I + 1.
      ENDIF.
    ENDDO.
    LOOP AT T_LINE INTO WA_LINE.
      CONCATENATE W_LINE WA_LINE-LINE INTO W_LINE SEPARATED BY SPACE.
    ENDLOOP.
    SHIFT W_LINE LEFT DELETING LEADING SPACE.
    WRITE: W_LINE.
    Input:
    <p style="something">Hello <strong>World</strong>!</p>
    Output:
    HELLO WORLD !
    Regards,
    Pritam

  • How to remove HTML tags from a String ?

    Hello,
    How can I remove all HTML Tags from a String ?
    Would you please to give me a simple example ?
    Best regards,
    Eric

    Here's some code I cooked up. I have created an object that processes code so that it can be incorporated directly into a project. There is some redundancy so that the it can be used in more than one way. Depending on your situation you might have to make the condition statement a little more sophisticated to catch stray ">" tags.
    I have also included a Tester application.
    //This removes Html tags from a String either by submitting the String during construction and then
    // calling getProcessedString() or
    // by simply calling " stringwithoutTags=removeHtmlTags(stringWithTagsSubmission); "
    //Note: This code assumes that all"<" tags are accompanied by a ">" tag in the proper order.
    public class HtmlTagRemover
         private String stringSubmission,processedString,stringBeingProcessed;
         private int indexOfTagStart,indexOfTagEnd;
         public HtmlTagRemover()
         public HtmlTagRemover(String s)
              removeHtmlTags(s);          
         public String removeHtmlTags(String s)
              stringSubmission=s;
              stringBeingProcessed=stringSubmission;
              removeNextTag();
              return processedString;
         private void removeNextTag()
              checkForNextTag();
              while((!(indexOfTagStart==-1||indexOfTagEnd==-1))&<indexOfTagEnd)
                   removeTag();
                   checkForNextTag();
              processedString=stringBeingProcessed;
         private void checkForNextTag()
              indexOfTagStart=stringBeingProcessed.indexOf("<");
              indexOfTagEnd=stringBeingProcessed.indexOf(">");
         private void removeTag()
              StringBuffer sb=new StringBuffer("");
              sb.append(stringBeingProcessed);
              sb.delete(indexOfTagStart,indexOfTagEnd+1);
              stringBeingProcessed=sb.toString();
         public String getProcessedString()
              return processedString;
         public String getLastStringSubmission()
              return stringSubmission;
    public class HtmlRemovalTester
         static void main(String[] args)
              String output;
              HtmlTagRemover h=new HtmlTagRemover();
              output="The processed String: "+h.removeHtmlTags("<Html tag>This is a test<another Html tag> string<yet another Html tag>.");
              output=output+"\n"+" The original string:"+h.getLastStringSubmission();
              System.out.print(output);

  • Out of Memory error while builng HTML String from a Large HashMap.

    Hi,
    I am building an HTML string from a large map oject that consits of about 32000 objects using the Transformer class in java. As this HTML string needs to be displayed in the JSP page, the reponse time was too high and also some times it is throwing out of memory error.
    Please let me know how i can implement the concept of building the library tree(folder structure) HTML string for the first set of say 1000 entries and then display in the web page and then detect an onScroll event and handle it in java Script functions and come back and build the tree for the next set of entries in the map and append this string to the previous one and accordingly display it.
    please let me know whether
    1. the suggested solution was the advisable one.
    2. how to build tree(HTML String) for a set of entries in the map while iterating over the map.
    3. How to detect a onScroll event and handle it.
    Note : Handling the events in the JavaScript functions and displaying the tree is now being done using AJAX.
    Thanks for help in Advance,
    Kartheek

    Hi
    Sorry,
    I haven't seen any error in the browser as this may be Out of memory error which was not handled. I got the the following error from the web logic console
    org.apache.struts.actions.DispatchAction">Dispatch[serviceCenterHome] to method 'getUserLibraryTree' returned an exceptionjava.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:276)
         at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:196)
         at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
         at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
         at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
         at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661)
         at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
    Caused by: java.lang.OutOfMemoryError
    </L_MSG>
    <L_MSG MN="ILHD-1109" PID="adminserver" TID="ExecuteThread: '14' for queue: 'weblogic.kernel.Default'" DT="2012/04/18 7:56:17:146" PT="WARN" AP="" DN="" SN="" SR="org.apache.struts.action.RequestProcessor">Unhandled Exception thrown: class javax.servlet.ServletException</L_MSG>
    <Apr 18, 2012 7:56:17 AM CDT> <Error> <HTTP> <BEA-101017> <[ServletContext(id=26367546,name=fcsi,context-path=/fcsi)] Root cause of ServletException.
    *java.lang.OutOfMemoryError*
    Please Advise.
    Thanks for your help in advance,
    Kartheek

  • Stripping HTML Tags from a String

    What's the best way to remove html tags from a string (i.e. user input)?

    Can you give an example? You can do substring, if your passing spaces between pages you can do a trim to the variable. Also look at the indexOf(). Look at methods relating to java.lang.String.

  • Parsing the FRAME tag from HTML pages

    Hello to everybody,
    I am trying to parse the A tags & the Frame tags from HTML pages. I have developed the code below, which works for the A tags but it does not work for the Frame tags. Is there any idea about this?
    private void getLinks() throws Exception {
         System.out.println(diskName);
    links=new ArrayList();
    frames=new ArrayList();
    BufferedReader rd = new BufferedReader(new FileReader(diskName));
    // Parse the HTML
    EditorKit kit = new HTMLEditorKit();
    HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
    doc.putProperty("IgnoreCharsetDirective", new Boolean(true));
    try {
         kit.read(rd, doc, 0);
    catch (RuntimeException e) {return;}
    // Find all the FRAME elements in the HTML document, It finds nothing
         HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.FRAME);
    while(it.isValid()) {
    SimpleAttributeSet s = (SimpleAttributeSet)it.getAttributes();
    String frameSrc = (String)s.getAttribute(HTML.Attribute.SRC);
         frames.add(frameSrc);
    // Find all the A elements in the HTML document, it works ok
    it = doc.getIterator(HTML.Tag.A);
    while (it.isValid()) {
    SimpleAttributeSet s = (SimpleAttributeSet)it.getAttributes();
    String link = (String)s.getAttribute(HTML.Attribute.HREF);
    int endOfSet=it.getEndOffset(),
    startOfSet=it.getStartOffset();
    String text=doc.getText(startOfSet,endOfSet-startOfSet);
    if (link != null)
         links.add(new Link(link,text));
    it.next();
    }

    Hello to everybody,
    I am trying to parse the A tags & the Frame tags from HTML pages. I have developed the code below, which works for the A tags but it does not work for the Frame tags. Is there any idea about this?
    private void getLinks() throws Exception {
         System.out.println(diskName);
    links=new ArrayList();
    frames=new ArrayList();
    BufferedReader rd = new BufferedReader(new FileReader(diskName));
    // Parse the HTML
    EditorKit kit = new HTMLEditorKit();
    HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
    doc.putProperty("IgnoreCharsetDirective", new Boolean(true));
    try {
         kit.read(rd, doc, 0);
    catch (RuntimeException e) {return;}
    // Find all the FRAME elements in the HTML document, It finds nothing
         HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.FRAME);
    while(it.isValid()) {
    SimpleAttributeSet s = (SimpleAttributeSet)it.getAttributes();
    String frameSrc = (String)s.getAttribute(HTML.Attribute.SRC);
         frames.add(frameSrc);
    // Find all the A elements in the HTML document, it works ok
    it = doc.getIterator(HTML.Tag.A);
    while (it.isValid()) {
    SimpleAttributeSet s = (SimpleAttributeSet)it.getAttributes();
    String link = (String)s.getAttribute(HTML.Attribute.HREF);
    int endOfSet=it.getEndOffset(),
    startOfSet=it.getStartOffset();
    String text=doc.getText(startOfSet,endOfSet-startOfSet);
    if (link != null)
         links.add(new Link(link,text));
    it.next();
    }

  • How to change inner content of HTML tag using HTMLDocument?

    I want to change the inner content of an HTML tag from a HTMLDocument. The tag is like
    <span id ="id1">Replace me</span>.
    So I want to change the text "Replace me" inside the span tag and replace it with an other text.
    I can get the span element using
    HTMLDocument.getElement("id1")
    I have tried many things with the Element instance i got from getElement. But I find no way to change the inner content of the HTML element. Any ideas?

    If I use JDK 1.5 the SPAN tag works, so I checked the core of the problem which is inserting HTML code in an HTML tag.
    setInnerHTML works fine for block tags like DIV but not if the tag is a leaf element like the SPAN tag. I have tried to use the following code for leaf elements:
    Element elem = m_htmlDocument.getElement(id);
    int nStartOffest = elem.getStartOffset();
    int nEndOffset = elem.getEndOffset();
    int nLength = nEndOffset - nStartOffest;
    m_htmlDocument.replace(nStartOffest, nLength, html, elem.getAttributes());
    This works, but only if the new HTML string does not contain HTML tags like a link <href..... >. If the string contains HTML tags the replace method masks all characters like < or >. So the link is not shown as link in the HTML page but as HTML text.
    The next thing I have tried is using
    m_htmlDocument.setOuterHTML(elem, html);
    This works too but it replaces the whole original HTML element like the SPAN tag.
    So there is still the question how to insert HTML text into a leaf Element in a HTMLDocument.

  • How to get the values from html:select? tag..?

    i tried with this, but its not working...
    <html:select styleClass="text" name="querydefs" property="shortcut"
                 onchange="retrieveOptions()" styleId="firstBox" indexed="true">
    <html:options collection="advanced.choices" property="shortcut" labelProperty="label" />
    </html:select>
                        <td align="left" class="rowcolor1">
                        <script language="javascript" type="text/javascript">
                              function retrieveOptions(){
                             var sel = document.querydefs.options;
                             var selectedOption = sel[sel.selectedIndex].value;
                             document.write(selectedOption);
                           </script>

    <td align="left" class="rowcolor1">
                        <script language="javascript" type="text/javascript">
                              function retrieveOptions(){
                             var sel = document.querydefs.options;
                             var selectedOption = sel[sel.selectedIndex].value;
                             document.write(selectedOption);
                           </script>This java script is not working at all..its not printing anything in document.write();
    This is code..
    <td class="rowcolor1" width="20%">
    <html:select styleClass="text" name="querydefs" property="shortcut"
                             onchange="retrieveSecondOptions()" styleId="firstBox"
                             indexed="true">
                             <html:options collection="advanced.choices" property="shortcut"
                                  labelProperty="label"  />
                        </html:select>i tried with this also. but no use..i'm not the getting the seleced option...
    function retrieveOptions(){
    firstBox = document.getElementById('firstBox');
                             if(firstBox.selectedIndex==0){
          return;
        selectedOption = firstBox.options[firstBox.selectedIndex].value;
    }actually , how to get the values from <html:select> ...?
    my idea is to know which value is selected from the combo box(<html:select> ) if that value is equal some string i have enable a hyperlink to open a popup window

  • Problem to display Animated Gif from HTML into JEditorPane

    I have a problem displaying animated gif that comes from URL (HTML) into JEditorPane.
    Let me show you the source I have:
    * @author Dobromir Gospodinov
    * @version 1.0
    * Date: Dec 6, 2002
    * Time: 6:47:53 PM
    package test.advertserver;
    import javax.swing.*;
    import java.awt.*;
    import java.io.IOException;
    public class Test {
         public static void main(String[] args) {
              JFrame frame = new JFrame();
              JEditorPane ed = new JEditorPane();
              try {
                   ed.setPage("http://localhost:8200/servlet?key=value");
              } catch (IOException e) {
                   e.printStackTrace();
              JPanel panel = new JPanel();
              panel.setPreferredSize(new Dimension(500, 500));
              panel.add(ed);
              frame.getContentPane().add(panel);
              frame.pack();
              frame.setVisible(true);
    }Part of the returned from servlet HTML includes an img tag:
    <img src="/images/MyAnimatedGif.gif" alt="animated gif comment" width="480" height="50"  border="0">Let us assume that MyAnimatedGif.gif has 10 frames and gif is looped - when the 10th is dipslayed it has to display the 1st and so on.
    JEditorPane displays frames from 1 to 10 correctly but does not start from the first again. Instead JEditorPane displays a broken image.
    I locate where the problem arise:
    JEditorPane has an HTMLEditorKit that creates javax.swing.text.html.ImageView instance for every IMG tag.
    And here is the problem:
    ImageView has an ImageObserver necessary for the asynchronous image download. ImageObserver has the imageUpdate method. But this imageUpdate method is never called with ALLBITS flag raised up. Instead, after the last frame of MyAnimatedGif.gif is downloaded the imageUpdate method is called with flag ERROR raised up. Obviously this is a bug of Sun's implementation. Finaly the flag ALLBITS has to be received for normal end of image observing. But ALLBITS flag does not come.
    So, can anybody help me how to load an animated gif within JEditorPane completely.
    Thank You in advance,
    Dobromir Gospodinov
    P.S. If somebody of you wants to debbug what happens within ImageView will have to implement it (and related classes too, because of the limited package visability) borrowing the source from Sun's ImageView.

    I'm also having this problem with java 1.4.1 I discovered that some animated gifs work fine, while others stop animating. Running with java 1.3.1 fixed the problem. I'm going to report this as a bug
    Here's my code:
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    public class AnimatedGifTester
    extends JFrame
    public static void main(String argv[])
    throws Exception
    new AnimatedGifTester();
    public AnimatedGifTester()
    throws Exception
    String[] images = new String[] {
    "http://www.gif.com/ImageGallery/Animated/Animals/Photographic/dog_running.gif",
    "http://www.gif.com/ImageGallery/Animated/Characters/Cartoon/java.gif",
    "http://www.webdeveloper.com/animations/bnifiles/anielg.gif",
    "http://www.webdeveloper.com/animations/bnifiles/cat2.gif",
    "http://images.animfactory.com/animations/animals/fish/big_fish_swimming_md_wht.gif",
    "http://www.webgenies.co.uk/images/martian.gif",
    "http://www.webdeveloper.com/animations/bnifiles/at_sign_rotating.gif",
    "http://www.webdeveloper.com/animations/bnifiles/arrow_1.gif",
    "http://www.gif.com/ImageGallery/Animated/Characters/Cartoon/javaacro.gif",
    "http://java.sun.com/products/java-media/2D/samples/suite/Image/duke.running.gif",
    "http://www.gif.com/ImageGallery/Animated/SouthPark/Cartoon/stan.gif"
    StringBuffer buffer = new StringBuffer("<html><body>");
    for (int idx = 0; idx < images.length; idx++)
    buffer.append("<img src='" + images[idx] + "'>");
    buffer.append("</body></html>");
    String html = buffer.toString();
    // save a copy of the html to open in a browser so we can see what it's
    // supposed to look like
    BufferedWriter writer = new BufferedWriter(new FileWriter("animatedGifTest.html"));
    writer.write(html);
    writer.close();
    JEditorPane editorPane = new JEditorPane("text/html", html);
    editorPane.setEditable(false);
    getContentPane().add(editorPane);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(new Dimension(400, 600));
    show();

  • Escape single quote from a String variable

    Hi,
    I have a String variable called "name" which i am using in my form tag.
    <form name=test action="test.jsp?fname=<%=name%>" method="post">
    But i am getting Javascript error if the "name" variable contains a string with some special characters like single quote( ' ).
    Plz help me to escape this special char from my String variable.
    Thanks..

    You need to url-encode the value using the URLEncoder class.
    http://java.sun.com/javase/6/docs/api/java/net/URLEncoder.html
    For example:
    <form name=test action="test.jsp?fname=<%=URLEncoder.encode(name, "ISO-8859-1")%>" method="post">

  • Problem while calling java function from html

    when i tried to call a java function from html i'm getting an error
    object don't support this property.
    what could be the reason.
    This is my html.
    I got this from this forum only.
    My applet is accessing the system property "user.home".
    I ran it in IE
    <DIV id="dvObjectHolder">Applet comes here</DIV>
    <br><br>
    <script>
    if(window.navigator.appName.toLowerCase().indexOf("netscape")!=-1){ // set object for Netscape:
         document.getElementById('dvObjectHolder').innerHTML = " <object ID='appletTest1' classid=\"java:test.class\"" +
    "height=\"0\" width=\"0\" onError=\"changeObject();\"" +
              ">" +
    "<param name=\"mayscript\" value=\"Y\">" +
    "<param name=\"archive\" value=\"sTest.jar\">" +
    "</object>";
    }else if(window.navigator.appName.toLowerCase().indexOf('internet explorer')!=-1){ //set object for IE
         document.getElementById('dvObjectHolder').innerHTML = "<object ID='appletTest1' classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\"" +
              " height=\"0\" width=\"0\" >" +
              " <param name=\"code\" value=\"test.class\" />" +
         "<param name=\"archive\" value=\"sTest.jar\">" +
              " </object>"
    </script>
    <LABEL id="lblOutputText">This text will be replaced by the applet</LABEL>
    <BR>
    <input value="Javascript to java" type=button onClick="document.appletTest1.fromJavaScript()">

    I tried this example using the repy given to an earlier post.
    But its not working with me.
    What i did in addition was adding plugin.jar to classpath to import netscape.javascript.*;
    Let me add some more details
    1) I'll add the stack trace
    2) my java progrma
    3) batch file to sign the applet.
    1) This is the stack trace i don't know whether u will undertand this
    load: class test.class not found.
    java.lang.ClassNotFoundException: test.class
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.FileNotFoundException: C:\FastranJava\AppletObject\bin\test\class.class (The system cannot find the path specified)
         at java.io.FileInputStream.open(Native Method)
         at java.io.FileInputStream.<init>(Unknown Source)
         at java.io.FileInputStream.<init>(Unknown Source)
         at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
         at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
         at sun.applet.AppletClassLoader.getBytes(Unknown Source)
         at sun.applet.AppletClassLoader.access$100(Unknown Source)
         at sun.applet.AppletClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 10 more
    Exception in thread "Thread-5" java.lang.NullPointerException
         at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
         at sun.plugin.AppletViewer.showAppletException(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    2) Java Program
    import netscape.javascript.*;
    import java.applet.*;
    public class test extends Applet
         private JSObject win;
         private JSObject outputLabel;
         private boolean buttonFromJavaClicked=false;
         checkJavaScriptEvent evt=new checkJavaScriptEvent();
         public void init()
              try
                   evt.start();
                   win=JSObject.getWindow(this);
                   outputLabel=(JSObject)win.eval("document.getElementById('lblOutputText')");
                   outputLabel.setMember("innerHTML", "<center><h1>From Init<br>Your Home directory" + System.getProperty("user.home") + "</h1></center>");
              catch(Exception e)
                   e.printStackTrace();
         public void fromJavaScript()
              buttonFromJavaClicked=true;          
         public void fromJavaScript2()
              System.out.println("Started Form JavaScript2");
              try
                   String strLbl="<center><h1>From JavaScript<br>Your Homedir:" + System.getProperty("user.home") + "</h1></center>";
                   outputLabel.setMember("innerHTML", strLbl);
              catch(Exception e)
                   e.printStackTrace();
         class checkJavaScriptEvent extends Thread
              public void run()
                   while(true)
                        if(test.this.buttonFromJavaClicked)
                             System.out.println("OK buttonfromjava is true");
                             test.this.buttonFromJavaClicked=false;
                             fromJavaScript2();
                        try
                             Thread.sleep(3000);
                        catch(Exception e)
                             e.printStackTrace();
    3) Batch file
    del *.cer
    del *.com
    del *.jar
    del *.class
    javac -classpath ".;C:\Program Files\Java\jre1.5.0_06\lib\plugin.jar" test.java
    keytool -genkey -keystore harm.com -keyalg rsa -dname "CN=Harm Meijer, OU=Technology, O=org, L=Amsterdam, ST=, C=NL" -alias harm -validity 3600 -keypass password -storepass password
    jar cf0 test.jar *.class
    jarsigner -keystore harm.com -storepass password -keypass password -signedjar sTest.jar test.jar harm
    del *.class

  • Path and file name problem when I want to download files from html

    Hi all,
    I want to write a small program to allow users download files from jsp file
    but the following files don't work .
    <%@ page language="java" import="java.net.*,java.io.*"%>
    <%@ page import ="java.util.*"%>
    <%
    try
    String SContent = request.getParameter("click");
    String SDocName = "temp.doc"; //  out put file File Name
    ServletOutputStream stream= response.getOutputStream(); // Getting ServletOutputStream
    response.setContentType("application/msword"); // Setting content type
    response.setHeader("Content-disposition","attachment;filename=\"" +SDocName+"\""); // To pop dialog box
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(SContent));
    int c;
    while ((c = in.read()) != -1){
               stream.write(c);
    in.close();
    stream.flush();
    catch(final IOException e)
    System.out.println ( "IOException." );
    catch(Exception e1)
    System.out.println ( "Exception." );
    %>I am so confuse, what is the path and file name I sould give ? for example my click should equal to http://******/Test/display.jsp?click=00-1

    Hi all,
    I got error at
    java.lang.IllegalStateException: getOutputStream() has already been called for this response
         org.apache.coyote.tomcat5.CoyoteResponse.getWriter(CoyoteResponse.java:599)
    if I want ot download file from html file.
    String SContent = request.getParameter("click");
    if I hard code like follow it work fine.
    String SContent ="C:/Project Coding.doc";
    what mistake I make.
    Thank you!

  • How to parse select lines in an html string?

    I've been writing a program to deal with demographic data and the first server it calls returns an xml string. However, the backup server returns an html string instead of an xml string, so the formatting is a bit different. I was going to use a regex as I did with the xml server, but regex's don't work that well with html. i was wondering if you could offer some advice on how to effectively parse the html string? It is in this format <html>
    <head>
    <meta name="Description" content="ZIP Code Demographics"/>
    <meta name="Keywords" content="zip, zip code, zipcode, demographics, 2000, county, lookup, city, state"/>
    <title>ZIP Code Demographics Lookup</title>
    <link rel="stylesheet" type="text/css" href="http://www.MelissaData.com/style.css" />
    </head>
    <body topmargin="0" onload="document.getElementById('text1').focus()">
    <div align="center">
    <!--Start of top.asp 9/2/08 Ray-->
    <script type='text/javaScript' src='http://www.melissadata.com/cgi-bin/lib.js'></script>
        <table align="center" border="0" cellpadding="0" cellspacing="0" width="744" style="font-size:8pt; font-family:Arial; color: #666666">
            <tr valign='middle'  height='24'>
                 <td align="left" rowspan=2><a href="/index.htm">
                    <img border="0" src="http://www.melissadata.com/home/new1207/MelissaData-logo.gif" alt="Melissa Data Home Page" /></a><img border="0" src="http://www.melissadata.com/home/new1207/1-800-number.gif" width="112" height="22" alt="Call 1-800-MELISSA for Data Quality Solutions" /></td>
                <td colspan='2' align="right">
                    <font size="1" face="Verdana">
                <script type="text/javaScript">var r=uCookie("r"); var s=uCookie("s"); var n=uCookie("n");
                    //document.write (document.cookie);
                    if (r == "YES" && s == "IN" && n != "" ) document.write ("Hello <b>" + n.replace(/\+/g," ") + "<\/b>   [<font size=1><a href=/user/signout.aspx>Sign out<\/a>, <a href=/user/user_account.aspx>My Account<\/a></font>]");else document.write (" <a href=/user/signin.aspx>Sign In<\/a> ");
                </script></font></td></tr>
            <tr height='24'>
                <form method="get" action="http://w2.melissadata.com/cgi-bin/search.asp">          
                <td align="right" height=30>               
                    <a href="/netcart/order1.aspx"><img border="0" src="http://www.melissadata.com/home/new1207/Hompage-shoppincart.gif" alt="Shopping Cart" /></a>
                    <a style="color: #666666" href="/netcart/order1.aspx">Buy</a>
                    | <a style="color: #666666" href="/cgi-bin/newsletters.asp">Newsletters</a> | Search
                    <input name="indata" style="font-size:7pt; font-family:Arial" size="10" /><input type="image" src="http://www.melissadata.com/home/new1207/hompage-arrow.gif" style="vertical-align: middle"  value="Search" name="submit1" />
        </td></form></tr>
        </table>
        <style="font-size:10pt; font-family:Arial; color: #0066cc" type="text/css">
        <table align="center" border="0" cellpadding="4" cellspacing="0" width="744">
            <tr>
                <td align="center" width="106">
                    <b><a style="text-decoration: none" href="/products/index.htm">Products</a></b></td>
                <td align="center" width="106">
                    <b><a style="text-decoration: none" href="/solutions/index.htm">Solutions</a></b></td>
                <td align="center" width="106">
                    <b><a style="text-decoration: none" href="/download.htm">Downloads</a> </b></td>
                <td align="center" width="106">
                    <b><a style="text-decoration: none" href="/tech/tech.html">Support</a> </font></td>
                <td align="center" width="106">
                    <b><a style="text-decoration: none" href="/resources/index.htm">Resources</a></b></td>
                <td align="center" width="106">
                    <b><a style="text-decoration: none" href="/lookups/index.htm">Lookups</a></b></td>
                <td align="center" width="106">
                    <b><a style="text-decoration: none" href="/cgi-bin/contact.asp">Contact Us</a></b></td></tr>   
        </table></style>
    <!-- Start Image BanAd.asp-->
    <div align=center><a href='/cgi-bin/BanAd.asp?id=135'><img alt='Click here' src='/cgi-bin/BanImage.asp?id=135'></a></div><!-- End Image BanAd.asp-->
    <!--TitleBorder in Shared.asp -->
    <table width="744" cellspacing=0 border=1 bgcolor="#F7F7F7"><tr><td align=left><font color="#ce0000" size="5">ZIP Code Demographics Lookup</font></td><form><td width=120 align=center><input title='Help for ZIP Code Demographics Lookup' type=button onClick=openHelpWindow('/lookups/help/zipdemo2000.asp') value=Help>  <a title='Lookups home page' href=/lookups/index.htm>Index</a></td></form></tr></table>
    <!--TitleBorder End-->
    <form action="ZipDemo2000.asp" name="Demo2000">
    <table width="400" class="Disp">
    <tr><td align="center"><b>Enter a 5-Digit ZIP Code</b>
        <input class="Disp" title="Enter a ZIP Code" id="text1" size="5" name="ZipCode" maxlength="5"/> <input type="submit" value="Submit"/>
    </td></tr>
    </table>
    </form>
    <table cellspacing="0" cellpadding="1" width="750" border="2" bgcolor="#ffffcc">
    <tr bgcolor="lightblue"><td colspan="4" align="center">Year 2000 Demographics of <br><b>ZIP Code 90041</b><br><b>LOS ANGELES, California</b><br><a href=mapzipv.asp?zip=90041>Map of ZIP Code</a></td></tr>
    <tr bgcolor="#bbffff"><td>TOTAL POPULATION [1]</td><td >P001</td></tr>
    <tr bgcolor="#bbffff"><td>Universe: Total population</td><td >P001</td></tr>
    <tr><td>   Total</td><td align=right ><b> 27,864</b></td></tr>
    <tr bgcolor="#bbffff"><td>URBAN AND RURAL [6]</td><td >P002</td></tr>
    <tr bgcolor="#bbffff"><td>Universe: Total population</td><td >P002</td></tr>
    <tr><td>   Total:</td><td align=right ><b> 27,864</b></td></tr>
    <tr><td>         Urban:</td><td align=right ><b> 27,864</b></td></tr>
    <tr><td>           Inside urbanized areas</td><td align=right ><b> 27,864</b></td></tr>
    <tr><td>           Inside urban clusters</td><td align=right ><b> 0</b></td></tr>
    <tr><td>         Rural</td><td align=right ><b> 0</b></td></tr>
    <tr><td>         Not defined for this file</td><td align=right ><b> 0</b></td></tr>
    <tr bgcolor="#bbffff"><td>RACE [8]</td><td >P007</td></tr>
    <tr bgcolor="#bbffff"><td>Universe: Total population</td><td >P007</td></tr>
    <tr><td>   Total:</td><td align=right ><b> 27,864</b></td></tr>
    <tr><td>         White alone</td><td align=right ><b> 13,429</b></td></tr>
    <tr><td>         Black or African American alone</td><td align=right ><b> 630</b></td></tr>
    <tr><td>         American Indian and Alaska Native alone</td><td align=right ><b> 242</b></td></tr>
    <tr><td>         Asian alone</td><td align=right ><b> 7,123</b></td></tr>
    <tr><td>         Native Hawaiian and Other Pacific Islander alone</td><td align=right ><b> 42</b></td></tr>
    <tr><td>         Some other race alone</td><td align=right ><b> 4,738</b></td></tr>
    <tr><td>         Two or more races</td><td align=right ><b> 1,660</b></td></tr>
    <tr bgcolor="#bbffff"><td>HISPANIC OR LATINO BY RACE [17]</td><td >P008</td></tr>
    <tr bgcolor="#bbffff"><td>Universe: Total population</td><td >P008</td></tr>
    <tr><td>   Total:</td><td align=right ><b> 27,864</b></td></tr>
    <tr><td>         Not Hispanic or Latino:</td><td align=right ><b> 17,109</b></td></tr>
    <tr><td>           White alone</td><td align=right ><b> 8,468</b></td></tr>
    <tr><td>           Black or African American alone</td><td align=right ><b> 555</b></td></tr>
    <tr><td>           American Indian and Alaska Native alone</td><td align=right ><b> 105</b></td></tr>
    <tr><td>           Asian alone</td><td align=right ><b> 7,053</b></td></tr>
    <tr><td>           Native Hawaiian and Other Pacific Islander alone</td><td align=right ><b> 30</b></td></tr>
    <tr><td>           Some other race alone</td><td align=right ><b> 73</b></td></tr>
    <tr><td>           Two or more races</td><td align=right ><b> 825</b></td></tr>
    <tr><td>         Hispanic or Latino:</td><td align=right ><b> 10,755</b></td></tr>
    <tr><td>           White alone</td><td align=right ><b> 4,961</b></td></tr>
    <tr><td>           Black or African American alone</td><td align=right ><b> 75</b></td></tr>
    <tr><td>           American Indian and Alaska Native alone</td><td align=right ><b> 137</b></td></tr>
    <tr><td>           Asian alone</td><td align=right ><b> 70</b></td></tr>
    <tr><td>           Native Hawaiian and Other Pacific Islander alone</td><td align=right ><b> 12</b></td></tr>
    <tr><td>           Some other race alone</td><td align=right ><b> 4,665</b></td></tr>
    <tr><td>           Two or more races</td><td align=right ><b> 835</b></td></tr>
    <tr bgcolor="#bbffff"><td>SEX BY AGE [49]</td><td >P012</td></tr>
    <tr bgcolor="#bbffff"><td>Universe: Total population</td><td >P012</td></tr>
    <tr><td>   Total:</td><td align=right ><b> 27,864</b></td></tr>
    <tr><td>         Male:</td><td align=right ><b> 13,324</b></td></tr>
    <tr><td>           Under 5 years</td><td align=right ><b> 862</b></td></tr>
    <tr><td>           5 to 9 years</td><td align=right ><b> 974</b></td></tr>
    <tr><td>           10 to 14 years</td><td align=right ><b> 872</b></td></tr>
    <tr><td>           15 to 17 years</td><td align=right ><b> 525</b></td></tr>
    <tr><td>           18 and 19 years</td><td align=right ><b> 511</b></td></tr>
    <tr><td>           20 years</td><td align=right ><b> 257</b></td></tr>
    <tr><td>           21 years</td><td align=right ><b> 287</b></td></tr>
    <tr><td>           22 to 24 years</td><td align=right ><b> 569</b></td></tr>
    <tr><td>           25 to 29 years</td><td align=right ><b> 969</b></td></tr>
    <tr><td>           30 to 34 years</td><td align=right ><b> 1,024</b></td></tr>
    <tr><td>           35 to 39 years</td><td align=right ><b> 1,140</b></td></tr>
    <tr><td>           40 to 44 years</td><td align=right ><b> 1,077</b></td></tr>
    <tr><td>           45 to 49 years</td><td align=right ><b> 987</b></td></tr>
    <tr><td>           50 to 54 years</td><td align=right ><b> 822</b></td></tr>
    <tr><td>           55 to 59 years</td><td align=right ><b> 647</b></td></tr>
    <tr><td>           60 and 61 years</td><td align=right ><b> 215</b></td></tr>
    <tr><td>           62 to 64 years</td><td align=right ><b> 270</b></td></tr>
    <tr><td>           65 and 66 years</td><td align=right ><b> 155</b></td></tr>
    <tr><td>           67 to 69 years</td><td align=right ><b> 258</b></td></tr>
    <tr><td>           70 to 74 years</td><td align=right ><b> 320</b></td></tr>
    <tr><td>           75 to 79 years</td><td align=right ><b> 252</b></td></tr>
    <tr><td>           80 to 84 years</td><td align=right ><b> 183</b></td></tr>
    <tr><td>           85 years and over</td><td align=right ><b> 148</b></td></tr>
    <tr><td>         Female:</td><td align=right ><b> 14,540</b></td></tr>
    <tr><td>           Under 5 years</td><td align=right ><b> 864</b></td></tr>
    <tr><td>           5 to 9 years</td><td align=right ><b> 949</b></td></tr>
    <tr><td>           10 to 14 years</td><td align=right ><b> 875</b></td></tr>
    <tr><td>           15 to 17 years</td><td align=right ><b> 534</b></td></tr>
    <tr><td>           18 and 19 years</td><td align=right ><b> 592</b></td></tr>
    <tr><td>           20 years</td><td align=right ><b> 285</b></td></tr>
    <tr><td>           21 years</td><td align=right ><b> 264</b></td></tr>
    <tr><td>           22 to 24 years</td><td align=right ><b> 600</b></td></tr>
    <tr><td>           25 to 29 years</td><td align=right ><b> 932</b></td></tr>
    <tr><td>           30 to 34 years</td><td align=right ><b> 1,035</b></td></tr>
    <tr><td>           35 to 39 years</td><td align=right ><b> 1,026</b></td></tr>
    <tr><td>           40 to 44 years</td><td align=right ><b> 1,131</b></td></tr>
    <tr><td>           45 to 49 years</td><td align=right ><b> 1,038</b></td></tr>
    <tr><td>           50 to 54 years</td><td align=right ><b> 970</b></td></tr>
    <tr><td>           55 to 59 years</td><td align=right ><b> 689</b></td></tr>
    <tr><td>           60 and 61 years</td><td align=right ><b> 261</b></td></tr>
    <tr><td>           62 to 64 years</td><td align=right ><b> 327</b></td></tr>
    <tr><td>           65 and 66 years</td><td align=right ><b> 208</b></td></tr>
    <tr><td>           67 to 69 years</td><td align=right ><b> 307</b></td></tr>
    <tr><td>           70 to 74 years</td><td align=right ><b> 482</b></td></tr>
    <tr><td>           75 to 79 years</td><td align=right ><b> 450</b></td></tr>
    <tr><td>           80 to 84 years</td><td align=right ><b> 331</b></td></tr>
    <tr><td>           85 years and over</td><td align=right ><b> 390</b></td></tr>
    <tr bgcolor="#bbffff"><td>MEDIAN AGE BY SEX [3]</td><td >P013</td></tr>
    <tr bgcolor="#bbffff"><td>Universe: Total population</td><td >P013</td></tr>
    <tr bgcolor="#bbffff"><td>Median age--</td><td >P013</td></tr>
    <tr><td>         Both sexes</td><td align=right ><b> 35.3</b></td></tr>
    <tr><td>         Male</td><td align=right ><b> 34.0</b></td></tr>
    <tr><td>         Female</td><td align=right ><b> 36.6</b></td></tr>
    <tr bgcolor="#bbffff"><td>HOUSEHOLDS [1]</td><td >P015</td></tr>
    <tr bgcolor="#bbffff"><td>Universe: Households</td><td >P015</td></tr>
    <tr><td>   Total</td><td align=right ><b> 9,375</b></td></tr>
    <tr bgcolor="#bbffff"><td>POPULATION IN HOUSEHOLDS [1]</td><td >P016</td></tr>
    <tr bgcolor="#bbffff"><td>Universe: Population in households</td><td >P016</td></tr>
    <tr><td>   Total</td><td align=right ><b> 26,409</b></td></tr>
    <tr bgcolor="#bbffff"><td>AVERAGE HOUSEHOLD SIZE [1]</td><td >P017</td></tr>
    <tr bgcolor="#bbffff"><td>Universe: Households</td><td >P017</td></tr>
    <tr><td>   Average household size</td><td align=right ><b> 2.82</b></td></tr>
    <tr bgcolor="#bbffff"><td>FAMILIES [1]</td><td >P031</td></tr>
    <tr bgcolor="#bbffff"><td>Universe: Families</td><td >P031</td></tr>
    <tr><td>   Total</td><td align=right ><b> 6,326</b></td></tr>
    <tr bgcolor="#bbffff"><td>POPULATION IN FAMILIES [1]</td><td >P032</td></tr>
    <tr bgcolor="#bbffff"><td>Universe: Population in families</td><td >P032</td></tr>
    <tr><td>   Total</td><td align=right ><b> 21,653</b></td></tr>
    <tr bgcolor="#bbffff"><td>AVERAGE FAMILY SIZE [1]</td><td >P033</td></tr>
    <tr bgcolor="#bbffff"><td>Universe: Families</td><td >P033</td></tr>
    <tr><td>   Average family size</td><td align=right ><b> 3.42</b></td></tr>
    </table>
    <!-- Start of bottom.asp-->
        <hr width="730" />
        <span style='font-size:8pt'>
        <a href="http://www.melissadata.com/enews/advisorarticles/index.htm">Articles</a> | 
        <a href="javascript:window.external.AddFavorite('http://www.melissadata.com/lookups/zipdemo2000.asp', 'ZIP Code Demographics Lookup')" target="_self">Bookmark</a> | 
        <a href="http://www.melissadata.com/cgi-bin/improve.asp?web">How Can We Improve?</a> | 
        <a href="http://www.melissadata.com/cgi-bin/batchprocessing.asp">Batch Processing</a> | 
        <a href="http://www.melissadata.com/cgi-bin/send.asp?Send2Friend">Email to Friend</a> | 
        <a href="http://www.melissadata.com/cgi-bin/catalogres.asp">Free Catalog</a> | 
        <a href="http://forum.melissadata.com/default.aspx">Forums</a> | 
        <a href="http://www.melissadata.com/terms-of-use.htm">Terms of Use</a>
        <font color="#ddddff"><br />  
        <script type="text/javascript"> var r=uCookie("r"); var f=uCookie("f"); var c=uCookie("c"); var l=uCookie("l");
            //document.write (r + ":" + f + ":" + c + ":" + l);</script></font></span>
    <!-- End of bottom.asp-->
    </div>
    </body>
    </html>.
    The numbers I wanted to extract are the age groups of "Under 5 years," "5 to 9 years," "10 to 14 years," and "15 to 17 years," from both male and female groups, which should add up to 8 numbers total. Here is the backup server portion of my program as well, so you can see what i'm doing.
    import java.net.*;
    import java.net.URL;
    import java.net.URLConnection;
    import java.net.HttpURLConnection;
    import java.io.*;
    import java.io.DataOutputStream;
    import java.io.BufferedReader;
    import java.io.StringReader;
    import java.io.InputStreamReader;
    import java.io.PrintStream;
    import java.util.Scanner;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.util.Arrays;
    public class TriParser
         static Scanner sc = new Scanner(System.in);
         public static int[] findValues(String text, String gender, String[] labels)
                Matcher m = Pattern.compile("<td>(.*?)</td>",
               Pattern.MULTILINE | Pattern.DOTALL).matcher(text);
                String allValues = m.find() ? m.group(1) : null; // TODO: handle if 'null' is returned!
                int[] values = new int[labels.length];
                for(int i = 0; i < labels.length; i++)
                  m = Pattern.compile(labels[i]+"[^>]+>(\\d+)").matcher(allValues);
                  if(m.find()) values[i] = Integer.parseInt(m.group(1));
                return values;
         public static void main(String[] args) throws Exception
            int zip;
            boolean validInteger;//indicates if zipcode is valid (has to be 5 digits)
            do
                    System.out.print("Enter a five-digit zipcode: ");
                    zip = sc.nextInt();
                    validInteger = true;
                    if((zip < 10000) || (zip > 99999))
                            validInteger = false;
                            System.out.println("Invalid Entry.  Please re-enter zipcode.");
            while(!validInteger);
            System.out.println(zip);     
            //String requestPart1 ="query=PREFIX+dc%3A++%3Chttp%3A%2F%2Fpurl.org%2Fdc%2Felements%2F1.1%2F%3E+%0D%0APREFIX+census%3A+%3Chttp%3A%2F%2Fwww.rdfabout.com%2Frdf%2Fschema%2Fcensus%2F%3E+%0D%0APREFIX+census1%3A+%3Ctag%3Agovshare.info%2C2005%3Ardf%2Fcensus%2Fdetails%2F100pct%2F%3E+%0D%0A%0D%0ADESCRIBE+%3Ftable+WHERE+%7B+%0D%0A+%3Chttp%3A%2F%2Fwww.rdfabout.com%2Frdf%2Fusgov%2Fgeo%2Fcensus%2Fzcta%2F";
            //String requestPart2 = "" + zip; // zipcode goes here
            //String requestPart3 ="%3E+census%3Adetails+%3Fdetails+.+%0D%0A+%3Fdetails+census1%3AtotalPopulation+%3Ftable+.+%0D%0A+%3Ftable+dc%3Atitle+%22SEX+BY+AGE+%28P012001%29%22+.+%0D%0A%7D%0D%0A&outputMimeType=text%2Fxml";
              String requestPart1 = "" + zip;
            String response = "";
            URL url = new URL("http://www.melissadata.com/lookups/zipdemo2000.asp?ZipCode="+requestPart1);
            URLConnection conn = url.openConnection();
            // Set connection parameters.
            conn.setDoInput (true);
            conn.setDoOutput (true);
            conn.setUseCaches (false);
            // Make server believe we are form data…
            conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
            DataOutputStream out = new DataOutputStream (conn.getOutputStream ());
            // Write out the bytes of the content string to the stream.
            out.writeBytes(requestPart1);
            out.flush ();
            out.close ();
            // Read response from the input stream.
            BufferedReader in = new BufferedReader (new
            InputStreamReader(conn.getInputStream ()));
            String temp;
            while ((temp = in.readLine()) != null)
                 response += temp + "\n"; // needs to be parsed to calculate the 4 numbers
            temp = null;
            in.close ();
              //System.out.println("Server response:\n" + response);
              // how to call the method:
              String[] ages = {"Under 5 years", "5 to 9 years", "10 to 14 years", "15 to 17 years"};
              String[] ages1 = {"Under 5 years"};
              String[] ages2 = {"5 to 9 years"};
              String[] ages3 = {"10 to 14 years"};
              String[] ages4 = {"15 to 17 years"};
              String female1 = Arrays.toString(findValues(response, "female", ages1));
              String female2 = Arrays.toString(findValues(response, "female", ages2));
              String female3 = Arrays.toString(findValues(response, "female", ages3));
              String female4 = Arrays.toString(findValues(response, "female", ages4));
              String female = female1 + "+" + female2 + "<" + female3 + ">" + female4 + "&";
              String male1 = Arrays.toString(findValues(response, "male", ages1));
              String male2 = Arrays.toString(findValues(response, "male", ages2));
              String male3 = Arrays.toString(findValues(response, "male", ages3));
              String male4 = Arrays.toString(findValues(response, "male", ages4));
              String male = male1 + "+" + male2 + "<" + male3 + ">" + male4 + "&";
              System.out.println(female);
              System.out.println(male);
            //Simplified string response, makes use of regular expressions
            //Start manipulation of numbers inside string
            int left = female.indexOf("[");
              int right = female.indexOf("]");
              // pull out the text inside the parens
              String parsed = female.substring(left+1, right);
              double parseddub = Double.parseDouble(parsed);
              //divide the group Under5Years into Under12Mo and 1to4Yr
              double Group1Adub = parseddub*.25;//25% for Under12Mo
              Group1Adub = Math.ceil(Group1Adub);
              int Group1A =(int)Group1Adub;
              double Group1Bdub = parseddub*.75;//75% for 1to4Yr
              Group1Bdub = Math.ceil(Group1Bdub);
              int Group1B =(int)Group1Bdub;
              int left2 = female.indexOf("+");
              int right2 = female.indexOf("<");
              // pull out the text inside the parens
              String parsed2 = female.substring(left2+2, right2-1);
              double parsed2dub = Double.parseDouble(parsed2);
              //divide the group 5to9Yr into 5Yr, 6to7Yr, and 8to9Yr
              double Group2Adub = parsed2dub*.2;//20% for 5Yr
              Group2Adub = Math.ceil(Group2Adub);
              int Group2A =(int)Group2Adub;
              double Group2Bdub = parsed2dub*.4;//40% for 6to7Yr
              Group2Bdub = Math.ceil(Group2Bdub);
              int Group2B =(int)Group2Bdub;
              double Group2Cdub = parsed2dub*.2;//20% for 8Yr
              Group2Cdub = Math.ceil(Group2Cdub);
              int Group2C =(int)Group2Cdub;
              double Group2Ddub = parsed2dub*.2;//20% for 9Yr
              Group2Ddub = Math.ceil(Group2Ddub);
              int Group2D =(int)Group2Ddub;
              int left3 = female.indexOf("<");
              int right3 = female.indexOf(">");
              // pull out the text inside the brackets
              String parsed3 = female.substring(left3+2, right3-1);
              int Group3A = Integer.valueOf(parsed3).intValue();
              int left4 = female.indexOf(">");
              int right4 = female.indexOf("&");
              // pull out the text inside the brackets
              String parsed4 = female.substring(left4+2, right4-1);
              int Group4A = Integer.valueOf(parsed4).intValue();
              int left5 = male.indexOf("[");
              int right5 = male.indexOf("]");
              String parsed5 = male.substring(left5+1, right5);
              double parsed5dub = Double.parseDouble(parsed5);
              //divide the group Under5Years into Under12Mo and 1to4Yr
              double Group5Adub = parsed5dub*.25;//25% for Under12Mo
              Group5Adub = Math.ceil(Group5Adub);
              int Group5A =(int)Group5Adub;
              double Group5Bdub = parsed5dub*.75;//75% for 1to4Yr
              Group5Bdub = Math.ceil(Group5Bdub);
              int Group5B =(int)Group5Bdub;     
              int left6 = male.indexOf("+");
              int right6 = male.indexOf("<");
              // pull out the text inside the parens
              String parsed6 = male.substring(left6+2, right6-1);
              double parsed6dub = Double.parseDouble(parsed6);
              //divide the group 5to9Yr into 5Yr, 6to7Yr, and 8to9Yr
              double Group6Adub = parsed6dub*.2;//20% for 5Yr
              Group6Adub = Math.ceil(Group6Adub);
              int Group6A =(int)Group6Adub;
              double Group6Bdub = parsed6dub*.4;//40% for 6to7Yr
              Group6Bdub = Math.ceil(Group6Bdub);
              int Group6B =(int)Group6Bdub;
              double Group6Cdub = parsed6dub*.2;//20% for 8Yr
              Group6Cdub = Math.ceil(Group6Cdub);
              int Group6C =(int)Group6Cdub;
              double Group6Ddub = parsed6dub*.2;//20% for 9Yr
              Group6Ddub = Math.ceil(Group6Ddub);
              int Group6D =(int)Group6Ddub;
              int left7 = male.indexOf("<");
              int right7 = male.indexOf(">");
              // pull out the text inside the brackets
              String parsed7 = male.substring(left7+2, right7-1);
              int Group7A = Integer.valueOf(parsed7).intValue();
              int left8 = male.indexOf(">");
              int right8 = male.indexOf("&");
              // pull out the text inside the brackets
              String parsed8 = male.substring(left8+2, right8-1);
              int Group8A = Integer.valueOf(parsed8).intValue();
              //female
              int Group1 = Group1A;
              int Group2 = Group1B + Group2A;
              int Group3 = Group2A + Group2B + Group2C;
              int Group4 = Group2C + Group2D + Group3A + Group4A;     
              //male
              int Group5 = Group5A;
              int Group6 = Group5B + Group6A;
              int Group7 = Group6A + Group6B + Group6C;
              int Group8 = Group6C + Group6D + Group7A + Group8A;
              System.out.println("Server response:\n" + "\n" + "Female");
              System.out.println("Under 12 Months:    " + Group1);
              System.out.println("1 to 4 Years Old:   " + Group2);
              System.out.println("5 to 8 Years Old:   " + Group3);
              System.out.println("8 to 17 Years Old:  " + Group4);
              System.out.println("\n" + "Male");
              System.out.println("Under 12 Months:    " + Group5);
              System.out.println("1 to 4 Years Old:   " + Group6);
              System.out.println("5 to 8 Years Old:   " + Group7);
              System.out.println("8 to 17 Years Old:  " + Group8);
    }Currently it functions using a regex, and executes, but doesn't return any numbers, only returns zeros...If you could help me out with this, that would be amazing! Thanks so much.

    hmm, is there a way to do it without an external API? Of course there is.
    looks like i have to download the API and the idea behind the program is to make it so multiple people running only java can run the program, without having to download APIs, ect, to make it run. Not sure if that is what JTidy entails, but is that what you were suggesting?Personally, I don't understand the resistance to using well-tested tools already in existence as opposed to trying to rewrite a shallow facsimile of said tools. You can distribute the JTidy library along with your application and save yourself a great deal of development and debugging effort.
    ~

Maybe you are looking for

  • Freezes on startup during password prompt

    Whenever I restart my computer it boots normally until the password prompt comes on. It still looks fine until i go to enter in a password. As soon as i begin to enter a password the color spinning wheel appears and will start spinning forever. I usu

  • Itunes amongs other apps wont open

    Hi, I seem to be having issues opening my itunes and other applications such as Safari, microsoft manager etc... everytime i try to open one of these applications it seems to want to open and then quickly closes. I have tried to remove Itunes complet

  • I erased iphoto from my macbook air. What can i do to reinstall it???

    I erased iphoto from my macbook air. What can i do to reinstall it???

  • How to run a file in trusted mode?

    Okay, so I have a .swf that I run on my PC, that communicates with other linux boxes, etc... across my network based on IP address.  It works great, once the folder that swf resides in is trusted in the Global Settings Manager. Now, here's the proble

  • MOVED: HELP PC wont boot up after bios flash

    This topic has been moved to Older MSI motherboards. https://forum-en.msi.com/index.php?topic=184216.0