Page 1 of 2 12 LastLast
Results 1 to 20 of 36
Like Tree1Likes

Thread: execute Java class from jsp page making problem

  1. #1
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    269
    Rep Power
    3

    Default execute Java class from jsp page making problem

    Hi!

    I want to execute a class from src folder in JSP page. But i have receiving the error only..,


    My Code is


    Java Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
        <%@page import="ServerInitiator" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>welcome</title>
    </head>
    <body>
    <%
      ServerInitiator ex = new ServerInitiator();
         %>
      hi
      </body>
    </html>
    my package structure is execute Java class from jsp page making problem-crb.png

    i have try by using the above, is their any perfect way to call this..,
    - Raj

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: execute Java class from jsp page making problem

    Not using the default package?
    That's usually not a good design choice.

    In any case, you haven't said what error you are getting.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    269
    Rep Power
    3

    Default Re: execute Java class from jsp page making problem

    Thank You for your response Mr.Tolls!

    i have changed the package name and execute it. But the out put is coming only "Hi" on browser (my static input), the java class main method is not executed..,
    execute Java class from jsp page making problem-fr.png

    execute Java class from jsp page making problem-dd.png

    Please guide me Mr.Tolls..,
    Last edited by raj.mscking@gmail.com; 04-14-2014 at 02:39 PM.
    - Raj

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    927
    Rep Power
    2

    Default Re: execute Java class from jsp page making problem

    main? Creating a new instance does not execute the main method automagically. What were you expecting to see?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: execute Java class from jsp page making problem

    Indeed; the main() is the starting point of a client application, its not used to run individual classes.

    On top of that output generated by a class is not going to magically appear in the webpage, you'd have to output it to the response first.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: execute Java class from jsp page making problem

    What does the no-argument constructor for ServerInitiator doing?
    If nothing, then nothing will happen.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    269
    Rep Power
    3

    Default Re: execute Java class from jsp page making problem

    Hi!

    Sorry for my late replay Mr.Tolls, Now only i back to lab.

    I can run the class and find the solution by as your idea. But

    In my war file i am calling the JFrame class. if i deploy it working well on my local machine Tomcat server thr is no error. But if i host it by "http://screenshare.hostjava.net/" tomcat server it show some error while running. the error is

    Java Code:
    org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class server.ServerInitiator
       org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
       org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
       org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
       org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    Thank You..,
    - Raj

  8. #8
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    269
    Rep Power
    3

    Default Re: execute Java class from jsp page making problem

    It is showing the error



    Java Code:
    type Exception report
    
    message An exception occurred processing JSP page /index.jsp at line 28
    
    description The server encountered an internal error that prevented it from fulfilling this request.
    
    exception
    
    org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 28
    
    25:   <%
    26:   try
    27:   {
    28: 	  ServerInitiator ex = new ServerInitiator();
    29: 	  ex.getRun();  
    30:   }
    31:   catch(Exception e)
    
    
    Stacktrace:
    	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    - Raj

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: execute Java class from jsp page making problem

    The NoClassDefFound implies you haven't got that class in your classpath, or you haven't got a suitable import statement on the JSP page.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    269
    Rep Power
    3

    Default Re: execute Java class from jsp page making problem

    Thank you for your response Mr.Tolls!

    But the same war file is working on my local tomcat server now. But the problem is while upload into the live server only i have the problem..,
    - Raj

  11. #11
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    927
    Rep Power
    2

    Default Re: execute Java class from jsp page making problem

    Then you are probably missing a library in the live server. Do you know which jar file contains the ServerInitiator class?

    BTW: if this class is supposed to popup a JFrame, then the JFrame will popup on the server, not on the browser/client.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  12. #12
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: execute Java class from jsp page making problem

    And since that server is probably a headless environment, it will just crash with an exception :)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  13. #13
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    269
    Rep Power
    3

    Default Re: execute Java class from jsp page making problem

    Hi Mr.SurfMan!

    Thank You!

    I am not using any jar, i have directly added my java class into inside the src folder and call on thr jsp page..,
    - Raj

  14. #14
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    927
    Rep Power
    2

    Default Re: execute Java class from jsp page making problem

    If you open the war file with winzip or anything similar, does it actually contain the ServerInitiator.class file?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  15. #15
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    269
    Rep Power
    3

    Default Re: execute Java class from jsp page making problem

    yes!

    i can find the class files on in side the folder of "WEB-INF\classes\server\ServerInitiator.class"
    Last edited by raj.mscking@gmail.com; 04-15-2014 at 02:47 PM. Reason: This is the correct directory path
    - Raj

  16. #16
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    269
    Rep Power
    3

    Default Re: execute Java class from jsp page making problem

    if you have interest, with your permission shall i send the source code Mr.surfMan ?..,
    - Raj

  17. #17
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    927
    Rep Power
    2

    Default Re: execute Java class from jsp page making problem

    I am pretty sure that your war is not supposed to contain the "AdminServer\build" directory. The classes directory should be inside the WEB-INF directory.
    gimbal2 likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  18. #18
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: execute Java class from jsp page making problem

    Correct. Standard webapp deployment rules; classes (complete with packages) go in WEB-INF/classes, jar libraries go in WEB-INF/lib
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  19. #19
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    269
    Rep Power
    3

    Default Re: execute Java class from jsp page making problem

    Dear Mr.SurfMan!

    this is the correct directory, where i have find the class path in side the war file "WEB-INF\classes\server\ServerInitiator.class" on my previous post i was edited my mistake..,

    Sorry for my mistake..,
    - Raj

  20. #20
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    927
    Rep Power
    2

    Default Re: execute Java class from jsp page making problem

    Can you first tell me what you expect to see if you start instantiating JFrames in a JSP?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Page 1 of 2 12 LastLast

Similar Threads

  1. Problems with making a class. New to Java.
    By zendavis in forum New To Java
    Replies: 9
    Last Post: 07-24-2011, 11:39 AM
  2. Create and Execute java class runtime
    By buntyindia in forum New To Java
    Replies: 1
    Last Post: 05-22-2011, 07:28 PM
  3. Newbie Need help Making Java to class and signing
    By altainta in forum Java Applets
    Replies: 1
    Last Post: 02-20-2011, 04:47 PM
  4. how to Import my Java Class in Jsp Page
    By pos in forum JavaServer Pages (JSP) and JSTL
    Replies: 20
    Last Post: 04-06-2010, 02:51 PM
  5. problems when I try to execute a jsp page
    By christina in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 08-01-2007, 12:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •