cwitr329
asked on
Making a Class file which if ran simply sends the user to a different URL
I have some javascript to check if the Java plugin is installed on a client machine before sending them to a java based or non-java based page. It is simply a timer waiting to see if the browser is able to enter an applet that will redirect the client to the Java page if it does, and if it doesnt enter the applet (No Java)shows how to install java. I am having trouble making the .class file which if entered will simply send the user to the right page. Can someone knowledgable in java make me one? If so, can the URL being send to be a param and be assignable in the applet javascrpt outside of the class file? Thank-you.
The URL can be specified as an applet parameter.
ASKER
Thank-you for the response. The one you linked me to was actually my question which I thought would work but couldnt get it compiled. Everytime I tried to compile the solution presented it gave me this error:
Unreported Exception Java.net.MalformedURLExcep tion; must be caught or declared to be thrown.
This is what I have in the class:
import java.applet.Applet;
import java.net.URL;
public class RedirectApplet extends Applet
{
public void start()
{
getAppletContext().showDoc ument(new URL("<http://www.objects.com.au>"));
}
}
Thanks
Unreported Exception Java.net.MalformedURLExcep
This is what I have in the class:
import java.applet.Applet;
import java.net.URL;
public class RedirectApplet extends Applet
{
public void start()
{
getAppletContext().showDoc
}
}
Thanks
public void start()
{
try
{
getAppletContext().showDoc ument(new URL("http://www.objects.com.au"));
}
catch(Exception e)
{
e.printStackTrace();
}
}
{
try
{
getAppletContext().showDoc
}
catch(Exception e)
{
e.printStackTrace();
}
}
ASKER
Thanks for that bit a code:
Here is what my class looks like:
import java.applet.Applet;
import java.applet.AppletContext;
import java.net.URL;
public class RedirectApplet extends Applet
{
public RedirectApplet()
{
}
public void start()
{
try
{
getAppletContext().showDoc ument(new URL("www.houseofnotes.com/Member/PrintNotesNow.aspx?noteid=<%=NoteID%>"));
}
catch(Exception exception)
{
exception.printStackTrace( );
}
}
}
I made a quick html to test it, and when ran it is not redirecting. Any idea why? See the applet run here: www.houseofnotes.com/testjava.html
Thanks
Here is what my class looks like:
import java.applet.Applet;
import java.applet.AppletContext;
import java.net.URL;
public class RedirectApplet extends Applet
{
public RedirectApplet()
{
}
public void start()
{
try
{
getAppletContext().showDoc
}
catch(Exception exception)
{
exception.printStackTrace(
}
}
}
I made a quick html to test it, and when ran it is not redirecting. Any idea why? See the applet run here: www.houseofnotes.com/testjava.html
Thanks
Any exceptions on the console? What is the value of NoteID
ASKER
No, just checked the Console and no exceptions. The note ID is a number being passed. It doesnt even try to redirect to the new URL, it just site there and on the bottom says the applet is running.
Any ideas?
Thanks
Any ideas?
Thanks
Try without the NoteID - does that work?
><applet code="RedirectApplet.class " codebase = "" width="32" height="32">
That is not loading the applet at my end.
Where is class ?
Try
<applet code="RedirectApplet.class " codebase = "." width="32" height="32">
That is not loading the applet at my end.
Where is class ?
Try
<applet code="RedirectApplet.class
I got it to load now. My java console says
java..net.MalformedUrlExce ption: no protocol: www.houseofnotes.com/Member/PrintNotesNow.aspx?noteid=<%=NoteID%>
So,add protocol and figure out why the JSP expression was not evaluated.
java..net.MalformedUrlExce
So,add protocol and figure out why the JSP expression was not evaluated.
Make that
getAppletContext().showDoc ument(new URL("http://www.houseofnotes.com/Member/PrintNotesNow.aspx?noteid=<%=NoteID%>"));
getAppletContext().showDoc
Thanks for the clarification guys.
>>If so, can the URL being send to be a param and be assignable in the applet javascrpt outside of the class file?
Will this do ?
-------------------------- -----
import java.applet.Applet;
import java.applet.AppletContext;
import java.net.URL;
public class RedirectApplet extends Applet
{
public RedirectApplet(){}
String noteid = getParameter("noteid");
public void start()
{
try
{
getAppletContext().showDoc ument(new URL("http://www.houseofnotes.com/Member/PrintNotesNow.aspx?noteid=" + noteid));
}
catch(Exception exception)
{
exception.printStackTrace( );
}
}
}
-------------------------- ---------- ---------- ---------- -
<applet code="RedirectApplet.class "
codebase = "."
width="32"
height="32">
<param name = "noteid" value = "2">
</applet>
>>If so, can the URL being send to be a param and be assignable in the applet javascrpt outside of the class file?
Will this do ?
--------------------------
import java.applet.Applet;
import java.applet.AppletContext;
import java.net.URL;
public class RedirectApplet extends Applet
{
public RedirectApplet(){}
String noteid = getParameter("noteid");
public void start()
{
try
{
getAppletContext().showDoc
}
catch(Exception exception)
{
exception.printStackTrace(
}
}
}
--------------------------
<applet code="RedirectApplet.class
codebase = "."
width="32"
height="32">
<param name = "noteid" value = "2">
</applet>
Yes it should be sent as a parameter - that's what I'd specified in my 2nd comment. Thanks for giving the implementation, rrz
We're a team.
ASKER
Thank-you for all your inputs. Gave them a try and getting a compilation error. It is saying <%=NoteID%> is not declared.
If I run my script without this applet, it runs fine. The above note id variable is passing a number from page to page (ASP.NET).
I will keep trying to trouble shoot. Seems like there should be a simply way to determine if a user has Java or not. If not, tell them how to get it. If so, send them on through. Guess not!
Thanks
If I run my script without this applet, it runs fine. The above note id variable is passing a number from page to page (ASP.NET).
I will keep trying to trouble shoot. Seems like there should be a simply way to determine if a user has Java or not. If not, tell them how to get it. If so, send them on through. Guess not!
Thanks
>> If I run my script without this applet, it runs fine.
You mean if you run your applet without the script, it runs file :)
>> The above note id variable is passing a number from page to page (ASP.NET).
Can you explain how the ASP .NET page interacts with your applet?
You mean if you run your applet without the script, it runs file :)
>> The above note id variable is passing a number from page to page (ASP.NET).
Can you explain how the ASP .NET page interacts with your applet?
You can set the value of an applet parameter using Javascript.
ASKER
The ASP.net page simply passed a number to the next page (<%=NoteID%>). So that variable could = 123. Now, when the applet you made starts, that means the client has Java, so I need to go to this page:
www.houseofnotes.com/Member/PrintNotesNow.aspx?noteid=<%=NoteID%>
Which would be rendered: www.houseofnotes.com/Member/PrintNotesNow.aspx?noteid=123
Like I said before, seems like it would be a simple solution but its not working at all.
Thanks,
Ryan
www.houseofnotes.com/Member/PrintNotesNow.aspx?noteid=<%=NoteID%>
Which would be rendered: www.houseofnotes.com/Member/PrintNotesNow.aspx?noteid=123
Like I said before, seems like it would be a simple solution but its not working at all.
Thanks,
Ryan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
cwitr329, Can you post your full applet including the HTML?
You should have split the points.
https://www.experts-exchange.com/questions/22457090/Java-class-file-that-when-ran-redirects-to-another-page-specified-by-a-param.html