Solved

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

Posted on 2002-06-18
6
155 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
xjc and jaxb 2 88
spring AOP 6 71
Set up Wildfly 10 8 319
spring example errors 33 200
HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now