Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2007

Tip: Looking for answers? Try searching our database.

To invoke a Java  ".class"  file from JSP

Thread view: 
Vivek - 30 Jan 2007 14:41 GMT
hi
I have 2 files,  a Java  ".class"  file  and a JSP file
I need to invoke the Java ".class"  file from the JSP file.
from the JSP file I have to pass command line arguments to the Java
".class"  file ( by command line arguments i mean the String args[] of
the "public static void main(string args[])"  ).

and i have to display the output of the Java ".class"  file in a web
page using JSP.

can anybody help me out.
gaurav v bagga - 30 Jan 2007 15:10 GMT
hi,

public static <T> void invokeMethodDynamically(Class klassType,
Class<T> argumentsType, String methodName, Object object,T
valueSentForMethod) throws SecurityException,
IllegalArgumentException, NoSuchMethodException,
IllegalAccessException, InvocationTargetException {
        Method method;
        method = klassType.getMethod(methodName, argumentsType);
        Object returnValue = method.invoke(object,valueSentForMethod);

    }

you can do something like this.

alternatively

you can use

<Object> o = Class.forName("class_name").newInstance();
then use o as per you needs

hope this helps

regards
gaurav
Alex Hunsley - 30 Jan 2007 19:57 GMT
> hi,
>
[quoted text clipped - 17 lines]
> <Object> o = Class.forName("class_name").newInstance();
> then use o as per you needs

Reflection should be avoided unless you can't do without it.

What is wrong with accessing the class directly, if he knows the class's
name?
E.g. if class is called MyThing:

MyThing.main(new String[] {"arg1", "arg2", "etc"});
Alex Hunsley - 31 Jan 2007 11:15 GMT
> hi,
>
[quoted text clipped - 17 lines]
> <Object> o = Class.forName("class_name").newInstance();
> then use o as per you needs

Reflection should be avoided unless you can't do without it.

What is wrong with accessing the class directly, if he knows the class's
name?
E.g. if class is called MyThing:

MyThing.main(new String[] {"arg1", "arg2", "etc"});
Alex Hunsley - 30 Jan 2007 20:08 GMT
> hi
> I have 2 files,  a Java  ".class"  file  and a JSP file
[quoted text clipped - 7 lines]
>
> can anybody help me out.

Should have asked already - why exactly do you want to do this? What is
the end aim?
Andy Dingley - 30 Jan 2007 20:36 GMT
> I have to pass command line arguments to the Java ".class"  file
> ( by command line arguments i mean the String args[] of the "public static void main(string args[])"  ).

You've answered your own question. Although this class has a method
signature that _allows_ it to be used as a command line app, it's
still just a plain old method that takes parameters. It doesn't
_have_to_ be used as a command line app. Give it some parameters and
you can call it quite happily from within JSP.
Alex Hunsley - 31 Jan 2007 11:13 GMT
> hi
> I have 2 files,  a Java  ".class"  file  and a JSP file
[quoted text clipped - 7 lines]
>
> can anybody help me out.

Should have asked already - why exactly do you want to do this? What is
the end aim?
Alex Hunsley - 31 Jan 2007 11:14 GMT
> hi
> I have 2 files,  a Java  ".class"  file  and a JSP file
[quoted text clipped - 7 lines]
>
> can anybody help me out.

Should have asked already - why exactly do you want to do this? What is
the end aim?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.