How to call java class file from jsp

hi
we need to call java classes (which are written separately in .java file )from jsp file. we need it for our project if anyone knows about please reply us.
bye
siva sankari

you can call the methods in a lot of ways. you could use scriptlets with the
<%@ page import="package.class"%> and then inside instantiate an object
<%
     MyClass mc = new MyClass(parameters if any);
     mc.theMethodYouWantToCall();
%>or as Madathil has stated,
or use the JSP tags
<jsp:useBean id="anyname" class="classname"/>and then use the getProperty tag
or even Custom Tags

Similar Messages

  • How to call java script function from JSP ?

    how to call java script function from JSP ?

    i have function created by java script lets say x and i want to call this function from jsp scriplet tag which is at the same page ..thanks

  • How to access variables declared in java class file from jsp

    i have a java package which reads values from property file. i have imported the package.classname in jsp file and also i have created an object for the class file like
    classname object=new classname();
    now iam able to access only the methods defined in the class but not the variables. i have defined connection properties in class file.
    in jsp i need to use
    statement=con.createstatement(); but it shows variable not declared.
    con is declared in java class file.
    how to access the variables?
    thanks

    here is the code
    * testbean.java
    * Created on October 31, 2006, 12:14 PM
    package property;
    import java.beans.*;
    import java.io.Serializable;
    public class testbean extends Object implements Serializable {
    public String sampleProperty="test2";
        public String getSampleProperty() {
            return sampleProperty;
    }jsp file
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import="java.sql.*,java.util.*"%>
    <html>
    <head>
    <title>Schedule Details</title>
    </head>
    <jsp:useBean id="ConProp" class="property.testbean"/>
    <body>
    Messge is : <jsp:getProperty name="msg" property="sampleProperty"/>
    <%
      out.println(ConProp.sampleProperty);
    %>
    </body>
    </html>out.println(ConProp.sampleProperty) prints null value.
    is this the right procedure to access bean variables
    thanks

  • How can i call java class file in jsp page

    Hai,
    i wants to call .class file in jsp page.
    my class file is in C:\jsdk\bin.
    Thanks

    I'm not entirely sure what you mean by "calling a class file", but I'm going to assume that you want to do something like the following in your page:
    <%
    MyClass myClass = new MyClass();
    myClass.someMethod();
    %>etc
    If that's the case, then all you have to do is make sure that the class is in the servlet engine's classpath. You'll probably also need to include an appropriate import statement at the top of the page.
    Hope that helps.

  • Call java class file into jsp file

    Hello experts,
    I wrote a class file which have validation functions it successfully created a class file of that java file.
    and I puted that class file into tomcat's ../WEB-INF/classes folder.
    And whenever I am going to execute the jsp page it give error like
    "regexFunctions cannot be resolved to a type"
    My class file is like follows,
    import java.util.regex.*;
        public class regexFunctions
        private static int SUCCESS = 0;
        private static int FAILURE = 1;
        private static int MISSING_INFO = -1;
        public static String ALL_STRING_REGEX = "^[a-zA-Z]+$";
        public static String ALL_NUMBER_REGEX = "[0-9]+";
    public static int checkForString(String inputtedValue)
             int retCode = FAILURE;
             if ((inputtedValue != null) && (inputtedValue.length() > 0))
                 Pattern pattern = Pattern.compile(ALL_STRING_REGEX);
                 Matcher matcher = pattern.matcher(inputtedValue);
                 if (matcher.find())
                     retCode = SUCCESS;
             return retCode;
    }My jsp page is like follows,
                <%
                     regexFunctions reg = new regexFunctions();
         String id = request.getParameter("txtId");
         int i = regexFunctions.checkForString(id);
               %>So Please Let Me Help Out...

    Put it into a package. Classes in packages can't access classes with no package, since about 2003.

  • How to create JAVA Class file from an exisitng JAVA file in JDEVELOPER

    Hi All,
    I have a file called abc.java and i need to generate a class for the same using JDEVELOPER. Please help me what are the steps to be followed. I'm totally new to JAVA and first time working on JDEVELOPER tool.
    Thanks in Advance !

    Being completely new to something is not an argument (or shall we be honest: an excuse?) to not read the manual.
    Just to note: I would pick Eclipse or Netbeans if you're completely new to java. You'll have more chance of finding help either in forums, mailing lists or Google searches. But if you must stick with JDeveloper, the forum is here:
    JDeveloper and ADF

  • How to call class file from jsp without creating packages

    i m using tomcat 5.5
    i stored my class file into WEB-INF\Class directory
    how to call that class file. from my jsp page.
    i got some error.
    i used package concept,that works fine.

    i m using tomcat 5.5
    i stored my class file into WEB-INF\Class directory
    how to call that class file. from my jsp page.
    i got some error.
    i used package concept,that works fine.Then use packages.
    As of Java1.4, you can no longer import classes from the default package (no package declared) into classes that are packaged.
    All Tomcat classes are in packages, including the compiled JSP.
    Therefore: Your classes need to be in a package inorder to be imported and used by the JSP.
    Why the problem? If you know it works with packages, why try not to use them?

  • How to call java class from pl/sql procedure ?

    Hello everyone,
    My query is..
    There is one pl/sql stored procedure which is doing some business logic and storing data in some columns of one table, suppose the table name is 'ABC' .. and the rest of columns of table ABC are getting updated using java class. Now my problem is whenever I insert data in ABC using store proc.. i have to call that java class so that it will update the rest columns ( why java class for updating the columns in ABC is ..because that logic cant be done from pl/sql proc.. it has to be done using java )
    and the other thing is.. oracle is in one machine and java is in another .. :(
    hope ..u can help me out !!
    Thank in advance !!

    but that updation have to be done from java code only.. we are using GIS tools .. have to create some shape files and update the column with that shape file.. so creation of shape file has to be done from java code only..
    so how to call java class file which is on another machine and oracle in another..

  • How to call a class file in a jsp without deploying anything in j2ee

    Hi,
    I am new in J2EE. I have some jsps, which I configured using web.properties(documentroot=c:/jsp/). I am able to get
    those pages by the web browser. I have some import statements in some jsps, now I
    am trying to access those page but it is failing, it says
    org.apache.jasper.JasperException: Unable to compile class for
    JSPD:\j2sdkee1.3\repository\pradip\web\_0002fLogin_0002ejspLogin_jsp_0.java:1:
    Class com.gui.UPMGuiGlobalConstants not found in import.
    import com.gui.UPMGuiGlobalConstants;
    Actually I have not deployed any class file or jsps.. Now my question is can I access
    these jsps without deploying anything, like can I put my .jar file in any j2ee
    directory(like lib or anywhere else, I already tried after putting in /lib) and restart the
    j2ee and use it. So how can I call a class file from a jsp without any kind of
    deployment?
    Please send me the reply as soon as possible.
    Regds,
    Pradip

    After you put the jar containing the class to import into the WEB-INF/lib directory, you still need to include it in the jsp.
    Putting the jar into the lib dir, will make it available to the vm, but as in any other java class, you still need to import it into the class, that the jsp will be compiled into.
    And you do that by putting
    <%@page import="com.gui.UPMGuiGlobalConstants" %>somewhere near the top of your jsp. (well you don't need to put it there, but it good style ;)
    That should do it.

  • How to call a .bat file from java code?

    How to call a .bat file from java code? and how can i pass parameters to that .bat file?
    Thanks in advance

    thanks for ur reply
    but still i am getting the same error.
    I am trying to run a .bat file of together tool, my code looks like below
    import java.lang.Runtime;
    import java.lang.Process;
    import java.io.File;
    class SysCall{
         public static void main(String args[]){
              String cmd="D://Borland//Together6.2//bin//Together.bat -script:com.togethersoft.modules.qa.QA -metrics out:D://MySamples//Metrics// -fmt:html D://Borland//Together6.2//samples//java//CashSales//CashSales.tpr";
              //String path="D://Borland//Together6.2//bin//Together.bat ";
              Runtime r= Runtime.getRuntime(); //Declare the system call
              try{
                   System.out.println("Before batch is called");
                   Process p=r.exec(cmd);
                   System.out.println(" Exit value =" + p.exitValue());
                   System.out.println("After batch is called");
              /*can produce errors which must be caught*/
              catch(Exception e) {
                   e.printStackTrace();
                   System.out.println (e.toString());
    I am getting the below exception
    Before batch is called
    java.lang.IllegalThreadStateException: process has not exited
    at java.lang.Win32Process.exitValue(Native Method)
    at SysCall.main(SysCall.java:17)
    java.lang.IllegalThreadStateException: process has not exited

  • How to call a .jar file from a java bean?

    any body knows how to call a .jar file from a java bean?

    Crosspost!
    http://forum.java.sun.com/thread.jspa?messageID=4349619

  • How to call a jar file from oracle forms (6i)

    Hi,
    I'm working with oracle 6i. I want to know that how to call a .jar file from forms menu. when I use HOST('<path>\test.jar') it is working in 'Client Server' any way. but the problem is I use application server in order to run my form. so my form is in the server and I run the form via clients web browser. in that case above solution will not work. if any body knows how to overcome this problem please reply.
    thanks.
    duminda

    I created a bean area and set the class name as implementation class. within that java bean class I called to a bat file which consists of the execution command of the jar file ( because i don't know how to call .jar file from my bean class directly).
    then i tried to run it in application server. its still not running.
    can you tell me what i have to do within my bean class? or can you suggest any solution?
    thank you.

  • Loading Java Class File in JSP page

    I'm trying to load a java class file from a jsp page.
    (e.g. MyFile.java <-- Source "MyFile.class<--Class file of MyFile.java")
    jsp page
    <%@ include file = "MyFile.class" %>
    <HTML> // HTML Tags are here
    MyFile.java
    A normal java source file that has "public static void main" in it.
    My jsp page can display it's contents, 'except' for showing e.g. "1235%%215648%%public%%$$@##" through out the page...
    My guess is that it can't display my java class file..
    Can anyone please help me solve this problem of mine ?
    Thanks in advance : )
    Yours Sincerely,
    RainbowEnergies

    This is my JSP file.
    <HTML>
    <HEAD>
    <TITLE>Activity Games</TITLE>
    </HEAD>
    <%
    String name = "";
    String id = "";
    name = session.getAttribute("name").toString();
    session.setAttribute("name",name);
    id = session.getAttribute("id").toString();
    session.setAttribute("id",id);
    %>
    <BODY bgcolor="#cc99ff" text="#000000" link="#E3E3E3" vlink="#CCCCCC" alink="#FF0000">
    <H3><%=name%>, you have enter Activity Games</H3>
    <%@ page import="Games.Lufia.*" %>
    <%Lufia lufia = new Lufia();%>
    </BODY>
    </HTML>
    After I execute...
    An error occurred at line: 18 in the jsp file: /jsp/ActivityGames.jsp
    error: File C:\Program Files\Apache Tomcat 4.0\webapps\website\WEB-INF\classes\Games\Lufia\Lufia.class does not contain type Games.Lufia.Lufia as expected, but type Lufia. Please remove the file, or make sure it appears in the correct subdirectory of the class path.
    Generated servlet error:
    C:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\website\jsp\ActivityGames$jsp.java:85: Class Games.Lufia.Lufia not found.
    Lufia lufia = new Lufia();
    But if I comment this out....
    This is my JSP file.
    <HTML>
    <HEAD>
    <TITLE>Activity Games</TITLE>
    </HEAD>
    <%
    String name = "";
    String id = "";
    name = session.getAttribute("name").toString();
    session.setAttribute("name",name);
    id = session.getAttribute("id").toString();
    session.setAttribute("id",id);
    %>
    <BODY bgcolor="#cc99ff" text="#000000" link="#E3E3E3" vlink="#CCCCCC" alink="#FF0000">
    <H3><%=name%>, you have enter Activity Games</H3>
    <%@ page import="Games.Lufia.*" %>
    <%//Lufia lufia = new Lufia();%> <--- comment this out.... (HERE)
    </BODY>
    </HTML>
    The page shows but did not run my java class file..
    Thanks again for trying to help me solve this problem of mine. : - )
    Regards,
    RainbowEnergies

  • How to restrict the .class file from decompilation

    Hi all,
    i got a security problem. i need all the java class files to be most secured. is there any to restriction on the java class files from decompilation. is that possible?. pls help me out. it's very urgent
    thanks in advance

    You can make it harder to understand the decompiled code if you use an obfuscator. (I don't have links to any, do a google search, or search these forums, it have been discussed here previously.)
    You cannot completely prevent decompilation, though. Obfuscating does not for example not mean that any passwords you have hardcoded in the source is secure.

  • How to decode  java class file to java file

    hi
    how to decode java class file into java file
    regards
    kedar

    Its really.......... really BAD.
    Write ur own code... or use open source code..
    Its a bad practice...
    however i am telling u ..there is DJ java decompiler.
    but mind it there are Obfuscator also....like codeshield and others
    take care...
    Alok

Maybe you are looking for

  • GetSymbolTypeName() is not working after the update??

    i just updated into the latest version of Edge. i was debugging when i found out that getSymbolTypeName() is not working anymore. any solution to this?

  • FCP won't open one of its own files.

    Hi, everyone. I have an fcp project that I need to update and modify. I tried opening it, and I got "File Error: Wrong Type". I read this previous post... http://discussions.apple.com/thread.jspa?messageID=8398246&#8398246 ...and followed its suggest

  • 52 Application document not fully posted

    Hi I am using IDOCS and after output,this is the status of the IDOC: 52 Application document not fully posted How can i see where the status is set in order to fix this warning and get a green status?This is an input idoc Thanks

  • Portlet - dataUrl JSF

    Hi, I have a requirement to make an AJAX call to a JSF Portlet to retrieve some data. I coed as per the steps given in Weblogic portal JSF whitepaper (page 90). But when i make the AJAX call to the dataUrl, i get the data with the mark-up as a portle

  • Mavericks clean install

    How do i perform a clean install of Mavericks?