Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Did you know there are services out there that can turn an Instagram feed into an RSS feed? I found some interesting exclusive Instagram content which I wanted to follow without signing up for yet another social media account. RSS to the rescue!
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

972 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