joelettuce
asked on
Connecting to URL (another jsp) and parse info (IN JSP ONLY)
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?
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("https://www.experts-exchange.com/");
URLConnection conn = ee.openConnection();
DataInputStream dis = new DataInputStream(conn.getIn putStream( ));
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
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("https://www.experts-exchange.com/");
URLConnection conn = ee.openConnection();
DataInputStream dis = new DataInputStream(conn.getIn
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
ASKER
Kotan, the error I receive is the following:
org.apache.jasper.compiler .ParseExce ption: /home/fantasy/java/scrapin g.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.h tml"/ >
</HEAD>
<BODY>
<%@ page import="java.net.*,java.io .*" %>
<%
try {
URL ee = new URL("https://www.experts-exchange.com/");
URLConnection conn = ee.openConnection();
DataInputStream dis = new DataInputStream(conn.getIn putStream( ));
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>
org.apache.jasper.compiler
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.h
</HEAD>
<BODY>
<%@ page import="java.net.*,java.io
<%
try {
URL ee = new URL("https://www.experts-exchange.com/");
URLConnection conn = ee.openConnection();
DataInputStream dis = new DataInputStream(conn.getIn
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for the quick response. The information provided was exactly as required.
Glad I could help and Thanx for the "A".
CJ
CJ
What is the errors you got?