Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

how jsp opens a web page ?

Thread view: 
richardchaven - 04 Mar 2007 00:39 GMT
I want to build a simple JSP to act as a proxt to retrieve web page
(xml documents, actually) for an AJAX page (which cannot request
documents outside its own domain).

Please point me at some examples or give me a class name to start
with.

Thanks
Arne Vajhøj - 04 Mar 2007 01:21 GMT
> I want to build a simple JSP to act as a proxt to retrieve web page
> (xml documents, actually) for an AJAX page (which cannot request
> documents outside its own domain).
>
> Please point me at some examples or give me a class name to start
> with.

Use a servlet instead of a JSP page.

Several JSP AJAX toolkits exist that comes with an
easy to extend servlet.

Arne
richardchaven - 04 Mar 2007 22:56 GMT
> Use a servlet instead of a JSP page.

I want to be able to deploy a minimum of files (ideally one) without
configuring anything. If I can use a jsp to get data from a different
page, that will be the simpliest.

I've seens a reference to a custom tag library that allows one to, for
instance, embed a quote from a different site in a JSP, so it seems
like this is theoretically possible.

Any ideas ?
Arne Vajhøj - 05 Mar 2007 03:56 GMT
>> Use a servlet instead of a JSP page.
>
[quoted text clipped - 7 lines]
>
> Any ideas ?

Try and take the body of servlet code below and copy
into a <% %> block in your JSP page.

But I warn you. You can easily get problems
with content type and blank lines when doing
what is servlet work in a JSP page.

Arne

================================================

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.net.*;

public class CopyServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
        try {
           URL url = new URL("http://www.foobar.dk/");
           HttpURLConnection con = (HttpURLConnection)url.openConnection();
           con.connect();
           if(con.getResponseCode() == HttpURLConnection.HTTP_OK) {
              InputStream is = con.getInputStream();
              byte[] b = new byte[1000];
              int n;
              while((n = is.read(b)) >= 0) {
                 String s = new String(b,0,n);
                 response.getOutputStream().println(s);
              }
              is.close();
           }
           con.disconnect();
        } catch (MalformedURLException e) {
           e.printStackTrace();
        } catch (FileNotFoundException e) {
           e.printStackTrace();
        } catch (IOException e) {
           e.printStackTrace();
        }
    }
}
Daniel Pitts - 04 Mar 2007 18:49 GMT
On Mar 3, 4:39 pm, "richardchaven" <goo...@thistooshallpass.org>
wrote:
> I want to build a simple JSP to act as a proxt to retrieve web page
> (xml documents, actually) for an AJAX page (which cannot request
[quoted text clipped - 4 lines]
>
> Thanks

you would probably be better off getting a real proxy.

We use Resin for our webapps, and Apache as our webserver.  Apache can
use ProxyPass to pass certain URLs to other sites.

Of course, there are plenty of other ways to do this :-).

Hope this helped,
Daniel.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.