[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to connect a servlet program to internet?.

Posted on 2004-11-25
25
Medium Priority
?
200 Views
Last Modified: 2013-11-24
Hi,
I have written a servlet program to scan the request ie what ever typed in the url address field i can able to receive in my program. is there any possibility to connect my servlet program to internet like

for eg: http://localhost:8084/pack/main/www.google.com

once i type www.gogle.com in the url after this local host and press enter na is there any possibility to connect to internet.


kindly help me:)
0
Comment
Question by:vihar123
  • 11
  • 9
  • 5
25 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677679
YEs. Open a url to the site you want
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677696
You'd be better off sending the page address as a form parameter
0
 
LVL 92

Expert Comment

by:objects
ID: 12677716
you can just do a redirect to the specified url.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:vihar123
ID: 12677736
hello objects,

how to redirect the page. pls give me some same code r link if possible.
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 12677744
response.sendRedirect(url);
0
 
LVL 92

Expert Comment

by:objects
ID: 12677752
0
 

Author Comment

by:vihar123
ID: 12677798
Hi objects,

Is there any possibilities to cache the page completely, html and  images and all completely.
0
 
LVL 92

Expert Comment

by:objects
ID: 12677817
not easily no.
0
 

Author Comment

by:vihar123
ID: 12677824
for me it is possible to read the html contents but not the images and all. can u help me:)
0
 
LVL 92

Expert Comment

by:objects
ID: 12677833
you need to parse the html and find image tags and download images

following examples show you ways to parse html:

http://www.javaalmanac.com/egs/javax.swing.text.html/GetLinks.html
http://www.javaalmanac.com/egs/javax.swing.text.html/GetText.html

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677873
The client browser will cache the content anyway
0
 

Author Comment

by:vihar123
ID: 12677885
is there any software to download the webpages not the complete website.
0
 
LVL 92

Expert Comment

by:objects
ID: 12677905
> The client browser will cache the content anyway

not really relevant
0
 
LVL 92

Expert Comment

by:objects
ID: 12677914
> is there any software to download the webpages not the complete website.

the links i posted above will dowload the page contents
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677915
>>not really relevant

Why not?
0
 

Author Comment

by:vihar123
ID: 12677916
i need to have a seperate content of the pages browsed r else any way to read from the browser content
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12677921
>>i need to have a seperate content of the pages browsed r else any way to read from the browser content

The browser just caches the files that have been requested
0
 

Author Comment

by:vihar123
ID: 12677926
no,  i am trying to make an algorithm for that i need the pages browsed seperately in my table for that only i am asking any way to read r download  the pages.
0
 
LVL 92

Expert Comment

by:objects
ID: 12677965
Did u look at the links I posted earlier
0
 

Author Comment

by:vihar123
ID: 12677973
i tried but i dont understand what the code does,very difficult for me to understand the code
0
 

Author Comment

by:vihar123
ID: 12677982
hi objects,

Do u have link from any other site r different links if so pls give me.that code is difficult for me to understand.
0
 
LVL 92

Expert Comment

by:objects
ID: 12678182
The code downlaods and parses a html page from a specific url allowing you to also download any additional resources referenced by page such as images.

0
 

Author Comment

by:vihar123
ID: 12683972
Hi objects,

i tried but i cannot able to retrive  the HTML r the images. i am pasting my code.
can u pls check whether i have any mistake.

class parsing
{
      public static void main(String args[])
      {
            String s="http://www.google.com";
            
            String ss=getText(s);
            System.out.println(ss);
            
      }
      public static String getText(String uriStr) {
        final StringBuffer buf = new StringBuffer(1000);
   
        try {
            // Create an HTML document that appends all text to buf
            HTMLDocument doc = new HTMLDocument() {
                  
                public HTMLEditorKit.ParserCallback getReader(int pos) {
                    return new HTMLEditorKit.ParserCallback() {
                        // This method is whenever text is encountered in the HTML file
                        public void handleText(char[] data, int pos) {
                              
                            buf.append(data);
                            buf.append('\n');
                        }
                    };
                }
            };
   
            // Create a reader on the HTML content
            URL url = new URI(uriStr).toURL();
            URLConnection conn = url.openConnection();
            System.out.println("entering");
            Reader rd = new InputStreamReader(conn.getInputStream());
   
            // Parse the HTML
            EditorKit kit = new HTMLEditorKit();
            kit.read(rd, doc, 0);
        } catch (MalformedURLException e) {
        } catch (URISyntaxException e) {
        } catch (BadLocationException e) {
        } catch (IOException e) {
        }
   
        // Return the text
        return buf.toString();
    }

      
}

0
 
LVL 92

Expert Comment

by:objects
ID: 12684081
hang while i find some code, did a similiar thing for a client recenlty.
0
 
LVL 92

Expert Comment

by:objects
ID: 12684182
Add the followining to your callback class where base is the context of the page being parsed (eg.http://www.google.com in your example above)  

        public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos)
        {
            try
            {
                if (t.equals(HTML.Tag.IMG))
                {
                    // <img> tag
   
                    // Get the img src
                       
                    String src = (String) a.getAttribute(HTML.Attribute.SRC);
                    URL u = new URL(base, src);
                    ImageIcon image = new ImageIcon(u);
                }
            }
            catch (Exception ex)
            {
                System.out.println(ex+": "+u);
            }
        }
    }
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month19 days, 9 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question