Solved

Connecting to URL (another jsp) and parse info (IN JSP ONLY)

Posted on 2002-06-18
6
177 Views
Last Modified: 2010-04-01
Relatively new to Java.  Understand how to do jsp, have located java code to conect to site using URLConnection object.  Can this java code be placed in jsp?  When I do this I get many errors.  I just want to be able to return the content of the page and parse the information that I want.  If I cannot place only in jsp, how do I compile servlet and call from jsp?

0
Comment
Question by:joelettuce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:kotan
ID: 7091475
That can be done in jsp.
What is the errors you got?

0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7092787
of course you can place java code in a jsp.. just put the code btw <% .... %>

e.g.

<%
  int myInt = 0;
%>

Now if you are Using URLConnection make sure you are importing the appropriate classes.

<%@ page import="java.net.*,java.io.*" %>

<%
        try {
            URL ee = new URL("http://www.experts-exchange.com/");
            URLConnection conn = ee.openConnection();
            DataInputStream dis = new DataInputStream(conn.getInputStream());
            String inputLine;

            while ((inputLine = dis.readLine()) != null) {
                // code that handles each line as it is read in
            }
            dis.close();
        } catch (MalformedURLException me) {
            // handle bad urls
        } catch (IOException ioe) {
            // handle IO errors when making connection or retrieve info etc
        }
%>

HTH,
CJ
0
 

Author Comment

by:joelettuce
ID: 7096757
Kotan, the error I receive is the following:

org.apache.jasper.compiler.ParseException: /home/fantasy/java/scraping.jsp(3,26) Attribute  has no value


cheekyci, when I enter the code you provided into the "Body"?  (Is this correct), I get the same error above.  The for the quick response, should be simple.

Here is the code:

<HTML>

<HEAD>
<jsp:include flush="/true"/  page="/components/header.html"/ >
</HEAD>

<BODY>

<%@ page import="java.net.*,java.io.*" %>

<%
       try {
           URL ee = new URL("http://www.experts-exchange.com/");
           URLConnection conn = ee.openConnection();
           DataInputStream dis = new DataInputStream(conn.getInputStream());
           String inputLine;

Alert(inputLine);

           while ((inputLine = dis.readLine()) != null) {
               // code that handles each line as it is read in
           }
           dis.close();
       } catch (MalformedURLException me) {
           // handle bad urls
       } catch (IOException ioe) {
           // handle IO errors when making connection or retrieve info etc
       }
%>

</BODY>
</HTML>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Accepted Solution

by:
cheekycj earned 75 total points
ID: 7096838
IMHO, I think this is the line causing the problem:

<jsp:include flush="/true"/  page="/components/header.html"/ >

try this:
<%@ page import="java.net.*,java.io.*" %>
<HTML>

<HEAD>
<jsp:include flush="true"  page="/components/header.html" />
</HEAD>

<BODY>



<%
      try {
          URL ee = new URL("http://www.experts-exchange.com/");
          URLConnection conn = ee.openConnection();
          DataInputStream dis = new DataInputStream(conn.getInputStream());
          String inputLine;

Alert(inputLine);

          while ((inputLine = dis.readLine()) != null) {
              // code that handles each line as it is read in
          }
          dis.close();
      } catch (MalformedURLException me) {
          // handle bad urls
      } catch (IOException ioe) {
          // handle IO errors when making connection or retrieve info etc
      }
%>

</BODY>
</HTML>
0
 

Author Comment

by:joelettuce
ID: 7105668
Thank you for the quick response.  The information provided was exactly as required.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 7105805
Glad I could help and Thanx for the "A".

CJ
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Let's recap what we learned from yesterday's Skyport Systems webinar.
Part One of the two-part Q&A series with MalwareTech.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

636 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