Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Making a Class file which if ran simply sends the user to a different URL

Posted on 2007-03-19
22
Medium Priority
?
232 Views
Last Modified: 2010-04-16
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.
0
Comment
Question by:cwitr329
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 5
  • +1
22 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 18750172
You can write an applet like the accepted solution here:

http://www.experts-exchange.com/Programming/Languages/Scripting/Q_22457090.html

0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18750179
The URL can be specified as an applet parameter.
0
 

Author Comment

by:cwitr329
ID: 18750244
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.MalformedURLException; 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().showDocument(new URL("<http://www.objects.com.au>"));
}
}



Thanks
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 86

Expert Comment

by:CEHJ
ID: 18750830
public void start()
{
    try
    {
        getAppletContext().showDocument(new URL("http://www.objects.com.au"));
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}
0
 

Author Comment

by:cwitr329
ID: 18751194
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().showDocument(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
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18751470
Any exceptions on the console? What is the value of NoteID
0
 

Author Comment

by:cwitr329
ID: 18751500
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
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18751537
Try without the NoteID - does that work?
0
 
LVL 28

Expert Comment

by:rrz
ID: 18751588
><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">
0
 
LVL 28

Expert Comment

by:rrz
ID: 18751700
I got it to load now.  My java console says  
java..net.MalformedUrlException: no protocol: www.houseofnotes.com/Member/PrintNotesNow.aspx?noteid=<%=NoteID%>
So,add protocol and figure out why the JSP expression was not evaluated.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18751859
>>  no protocol

Ah, so you need it like "http://...."
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18751879
Make that

getAppletContext().showDocument(new URL("http://www.houseofnotes.com/Member/PrintNotesNow.aspx?noteid=<%=NoteID%>"));
0
 
LVL 28

Expert Comment

by:rrz
ID: 18752044
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().showDocument(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>
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18752076
Yes it should be sent as a parameter - that's what I'd specified in my 2nd comment. Thanks for giving the implementation, rrz
0
 
LVL 28

Expert Comment

by:rrz
ID: 18752090
We're a team.
0
 

Author Comment

by:cwitr329
ID: 18752972
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
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18753505
>> 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?
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18753513
You can set the value of an applet parameter using Javascript.
0
 

Author Comment

by:cwitr329
ID: 18757703
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
0
 
LVL 28

Accepted Solution

by:
rrz earned 2000 total points
ID: 18760715
I just tried with this applet.
-----------------------------------------  
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().showDocument(new URL("http://www.houseofnotes.com/Member/PrintNotesNow.aspx?noteid=" + noteid));
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
    }
}
---------------------------------------------------------
and in the HTML
------------------------------------------------------------
<applet code="RedirectApplet.class"
        codebase = "."
        width="32"
        height="32">
<param name = "noteid"  value = "123">
</applet>
--------------------------------------------------------
It redirects but ends up at
http://www.houseofnotes.com/Browser/ErrorPage.aspx?error=401 
So, the applet works.  If change to
<param name = "noteid"  value = "zzz">
It goes to  
http://www.houseofnotes.com/Member/PrintNotesNow.aspx?noteid=zzz
which displays message  
Server Error in '/' Application. Input string was not in a correct format.  
Your problem seems to be in ASP.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18760848
cwitr329, Can you post your full applet including the HTML?
0
 
LVL 28

Expert Comment

by:rrz
ID: 18809044
You should have split the points.
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

670 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