Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2002-06-18
6
Medium Priority
?
184 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
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!

 
LVL 19

Accepted Solution

by:
cheekycj earned 300 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

704 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