Though I am not sure as to what you are trying to achieve, you are getting the mentioned error because the URL constructor (the call new URL() ) throws a checked exception which you need to either catch or make the method have a throws clause.
try {
URL url = new URL("someURL");
} catch(MalformedURLException mue) {
// received an invalid url
}
OR
public void doSomething() throws MalformedURLException {
URL url = new URL("someURL");
}
And BTW, scriptlets are a strict no-no for a variety of reasons. Plus, it would be kind of difficult for you to get into J2EE if your basic Java concepts aren't clear enough.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
Since you can manipulate the listener, something like this should be of some use to you:
package home.projects.daniweb;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class URLTester {
public static void main(String args[]) {
String url = "http://www.google.com/";
try {
InputStream in = null;
try {
// Open a connection to the resource specified in 'url' and grab hold
// of the stream.
URL urlObj = new URL(url);
in = urlObj.openStream();
// Spit the response to the screen
BufferedReader bufIn = new BufferedReader(new InputStreamReader(in));
System.out.println("RESPONSE BEGINS\n");
String str;
while((str = bufIn.readLine()) != null) {
System.out.println(str);
}
System.out.println("RESPONSE ENDS\n");
} finally {
if(in != null) {
in.close();
}
}
} catch(Exception e) {
System.out.println("An exception has occured; " + e.getMessage());
}
}
}
If you are relying on a user input and if the action for that is well defined e.g. a user clicking on the logout link, you can code it as a simple HTML page:
<html>
<head>
<script type="text/javascript">
// Some script
</script>
</head>
<body>
<a href="/setPresence.cfm?user=bob&isOnline=0">Logout</a>
</body>
</html>
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734