Solved

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

Posted on 2002-06-18
6
173 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
Independent Software Vendors: 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Configuring Remote Assistance for use with SCCM
How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

710 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