how to connect a servlet program to internet?.

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:)
vihar123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
YEs. Open a url to the site you want
0
CEHJCommented:
You'd be better off sending the page address as a form parameter
0
objectsCommented:
you can just do a redirect to the specified url.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

vihar123Author Commented:
hello objects,

how to redirect the page. pls give me some same code r link if possible.
0
objectsCommented:
response.sendRedirect(url);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vihar123Author Commented:
Hi objects,

Is there any possibilities to cache the page completely, html and  images and all completely.
0
objectsCommented:
not easily no.
0
vihar123Author Commented:
for me it is possible to read the html contents but not the images and all. can u help me:)
0
objectsCommented:
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
CEHJCommented:
The client browser will cache the content anyway
0
vihar123Author Commented:
is there any software to download the webpages not the complete website.
0
objectsCommented:
> The client browser will cache the content anyway

not really relevant
0
objectsCommented:
> is there any software to download the webpages not the complete website.

the links i posted above will dowload the page contents
0
CEHJCommented:
>>not really relevant

Why not?
0
vihar123Author Commented:
i need to have a seperate content of the pages browsed r else any way to read from the browser content
0
CEHJCommented:
>>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
vihar123Author Commented:
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
objectsCommented:
Did u look at the links I posted earlier
0
vihar123Author Commented:
i tried but i dont understand what the code does,very difficult for me to understand the code
0
vihar123Author Commented:
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
objectsCommented:
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
vihar123Author Commented:
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
objectsCommented:
hang while i find some code, did a similiar thing for a client recenlty.
0
objectsCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.