Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > To invoke a Java ".class" file from JSP

Reply
Thread Tools

To invoke a Java ".class" file from JSP

 
 
Vivek
Guest
Posts: n/a
 
      01-30-2007
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.

 
Reply With Quote
 
 
 
 
gaurav v bagga
Guest
Posts: n/a
 
      01-30-2007
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


 
Reply With Quote
 
 
 
 
Alex Hunsley
Guest
Posts: n/a
 
      01-30-2007
gaurav v bagga wrote:
> 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


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"});
 
Reply With Quote
 
Alex Hunsley
Guest
Posts: n/a
 
      01-30-2007
Vivek wrote:
> 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.
>


Should have asked already - why exactly do you want to do this? What is
the end aim?
 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      01-30-2007
On 30 Jan, 14:41, "Vivek" <(E-Mail Removed)> wrote:

> 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.

 
Reply With Quote
 
Alex Hunsley
Guest
Posts: n/a
 
      01-31-2007
Vivek wrote:
> 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.
>


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

 
Reply With Quote
 
Alex Hunsley
Guest
Posts: n/a
 
      01-31-2007
Vivek wrote:
> 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.
>


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

 
Reply With Quote
 
Alex Hunsley
Guest
Posts: n/a
 
      01-31-2007
gaurav v bagga wrote:
> 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


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"});
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP invoke Servlet thiagoalgo Java 2 04-09-2007 11:06 PM
How To invoke a Applet from a Java File ??? Vivek Java 3 02-22-2007 02:54 PM
Declaring a variable in one JSP file and accessing it in another JSP file anubhakhurana@gmail.com Java 8 10-11-2006 01:15 AM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
How to get the html output of a local JSP page from my Java code, or use a JSP as an HTML templates. DigitalUncle Java 0 11-02-2004 05:22 PM



Advertisments