Page 2 of 2 FirstFirst 12
Results 21 to 36 of 36
Like Tree1Likes

Thread: execute Java class from jsp page making problem

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

    Default Re: execute Java class from jsp page making problem

    Have you got the full stack trace?
    NoClassDefFound usually has a causing exception.
    This is not necessarily a ClassNotFoundException, but could be an exception during the class construction (eg an exception thrown in a static initialiser).

    Also post any static initialiser code (including an static attributes) that exist in that class.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  2. #22
    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!

    In my project when user visit the jsp page it should open a JFrame, By using the JFrame i will share the screen from client to server, this is my server code.
    This code is working well on my Local Tomcat server Mr.SurfMan..,

    Thank You..,
    - Raj

  3. #23
    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

    This is my JSP code

    Java Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
        <%@page import="server.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>
     
      <%
      try
      {
    	  ServerInitiator ex = new ServerInitiator();
    	  ex.getRun();  
      }
      catch(Exception e)
      {
    	  e.getMessage();
      }
         %>
      hi
      </body>
    </html>

    this is my calling class

    Java Code:
    package server;
    
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    import javax.swing.JApplet;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    
    
    public class ServerInitiator{
        //Main server frame
        private static JFrame frame = new JFrame();
        
        //JDesktopPane represents the main container that will contain all
        //connected clients' screens
        private JDesktopPane desktop = new JDesktopPane();
        
        /*public static void main(String args[]){
            String port = "1527";
          
            new ServerInitiator().initialize(Integer.parseInt(port));
    
        }*/
        public void getRun()
        {
        	String port = "1527";
            
            new ServerInitiator().initialize(Integer.parseInt(port));
        }
    
        public void initialize(int port){
    
            try {
                ServerSocket sc = new ServerSocket(port);
                //Show Server GUI
                drawGUI();
                //Listen to server port and accept clients connections
                while(true){
                    Socket client = sc.accept();
                    System.out.println("New client Connected to the server");
                    //Per each client create a ClientHandler_new
                    new ClientHandler(client,desktop);
                     
          
                }
                
            } catch (IOException ex) {
                ex.printStackTrace();
            }
           
        }
    
        /*
         * Draws the main server GUI
         */
        public void drawGUI(){
                frame.setBounds(100, 100,200,200);
                frame.add(desktop,BorderLayout.CENTER);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                //Show the frame in a maximized state
                frame.setExtendedState(frame.getExtendedState()|JFrame.MAXIMIZED_BOTH);
                frame.setVisible(true);
               
        }
    }
    Thank You..,


    This is my Link http://screenshare.hostjava.net/AdminServer/
    Last edited by raj.mscking@gmail.com; 04-15-2014 at 03:21 PM.
    - Raj

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

    Default Re: execute Java class from jsp page making problem

    Java Code:
    private static JFrame frame = new JFrame();
    There you go.
    This is running on the server.
    The server JRE is (as gimbal said earlier) headless.

    The Java code in a JSP runs on the server. It does not run on the client...that's what applets are for.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #25
    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 Mr.Tolls!

    what have to do to run my Java Class on the JSP page..,

    what changes i have to do Mr.Tolls..,

    Guide me please..,
    - Raj

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

    Default Re: execute Java class from jsp page making problem

    First off, don't think of it as running on a JSP page.
    You are not running it on the JSP page.
    You are wanting to run it on the client browser.
    And the only way to run Java on a client browser is through an applet.

    So you need an applet.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Quote Originally Posted by Tolls View Post
    First off, don't think of it as running on a JSP page.
    You are not running it on the JSP page.
    You are wanting to run it on the client browser.
    And the only way to run Java on a client browser is through an applet.

    So you need an applet.
    Or webstart, probably the only real goal here is to run a java application on the client, it doesn't have to be -in- the browser.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #28
    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 Mr.Tolls!

    This is my JFrame class

    Java Code:
    
    package remoteserver;
    
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    import javax.swing.JApplet;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    
    
    public class ServerInitiator{
        //Main server frame
        private static JFrame frame = new JFrame();
        
        //JDesktopPane represents the main container that will contain all
        //connected clients' screens
        private JDesktopPane desktop = new JDesktopPane();
        
        public static void main(String args[]){
            String port = "1527";
          
            new ServerInitiator().initialize(Integer.parseInt(port));
    
        }
    
        public void initialize(int port){
    
            try {
                ServerSocket sc = new ServerSocket(port);
                //Show Server GUI
                drawGUI();
                //Listen to server port and accept clients connections
                while(true){
                    Socket client = sc.accept();
                    System.out.println("New client Connected to the server");
                    //Per each client create a ClientHandler_new
                    new ClientHandler(client,desktop);
                     
          
                }
                
            } catch (IOException ex) {
                ex.printStackTrace();
            }
           
        }
    
        /*
         * Draws the main server GUI
         */
        public void drawGUI(){
                frame.setBounds(100, 100,200,200);
                frame.add(desktop,BorderLayout.CENTER);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                //Show the frame in a maximized state
                frame.setExtendedState(frame.getExtendedState()|JFrame.MAXIMIZED_BOTH);
                frame.setVisible(true);
               
        }
    }

    This is My Applet Class which i have changed. But My problem is unable to custom the JJDesktopPane & JInternalFrame frames too..,

    Java Code:
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package remoteserver;
    
    import java.awt.BorderLayout;
    import java.awt.Button;
    import java.awt.Checkbox;
    import java.awt.CheckboxGroup;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.Graphics;
    import java.awt.TextField;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    import javax.swing.JApplet;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    
    /**
     *
     * @author Android
     */
    public class ActionExample extends JApplet implements ActionListener 
    {
    
         Button okButton; 
          String port = "1527";
          ServerInitiator sr;
          Container pane;
          
          private static JFrame frame = new JFrame();
        
        //JDesktopPane represents the main container that will contain all
        //connected clients' screens
        private JDesktopPane desktop = new JDesktopPane();
    
         public void init()  
         { 
      // Now we will use the FlowLayout 
              //setLayout(new FlowLayout()); 
              okButton = new Button("Action!"); 
              add(okButton); 
    
      // Attach actions to the components 
              okButton.addActionListener(this); 
             }
    
     // Here we will show the results of our actions 
    
     // When the button is clicked this method will get automatically called 
     // This is where you specify all actions.
    
            public void actionPerformed(ActionEvent evt)  
             { 
      // Here we will ask what component called this method 
                  if (evt.getSource() == okButton)  
       // So it was the okButton, then let's perform his actions 
       // Let the applet perform Paint again. 
       // That will cause the aplet to get the text out of the textField 
       // again and show it. 
           
        
                  initialize(Integer.parseInt(port));
    
      // Actions of the wrongButton 
         } 
    public void drawGUI(){
                frame.setBounds(100, 100,200,200);
                frame.add(desktop,BorderLayout.CENTER);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                //Show the frame in a maximized state
                frame.setExtendedState(frame.getExtendedState()|JFrame.MAXIMIZED_BOTH);
                frame.setVisible(true);
               
        }
    
     public void initialize(int port){
    
            try {
                ServerSocket sc = new ServerSocket(port);
                //Show Server GUI
                drawGUI();
                //Listen to server port and accept clients connections
                while(true){
                    Socket client = sc.accept();
                    System.out.println("New client Connected to the server");
                    //Per each client create a ClientHandler_new
                    new ClientHandler(client,desktop);
                     
          
                }
                
            } catch (IOException ex) {
                ex.printStackTrace();
            }
           
        }
    }
    This is my Handler Class for access by JFrame / JApplat

    Java Code:
    package remoteserver;
    
    
    
    
    
    import java.awt.BorderLayout;
    import java.awt.Rectangle;
    import java.beans.PropertyVetoException;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.net.Socket;
    import javax.swing.JDesktopPane;
    import javax.swing.JInternalFrame;
    import javax.swing.JPanel;
    import javax.swing.JOptionPane;
    import javax.swing.JFrame;
    class ClientHandler extends Thread {
    
        private JDesktopPane desktop = null;
        private Socket cSocket = null;
        private JInternalFrame interFrame = new JInternalFrame("Client Screen",
                                                                true, true, true);
        private  JPanel cPanel = new JPanel();
        
        public ClientHandler(Socket cSocket, JDesktopPane desktop) {
            JOptionPane.showMessageDialog(cPanel,"Client Connected");
            this.cSocket = cSocket;
            this.desktop = desktop;
            start();
        }
    
        /*
         * Draw GUI per each connected client
         */
        public void drawGUI(){
            interFrame.setLayout(new BorderLayout());
            interFrame.getContentPane().add(cPanel,BorderLayout.CENTER);
           // interFrame.setSize(100,100);
            interFrame.setBounds(100, 100,200,200);
            desktop.add(interFrame);
            desktop.setBounds(100, 100,200,200);
           
            //this allows to handle KeyListener events
            cPanel.setFocusable(true);
            interFrame.setVisible(true);
        }
    
        public void run(){
    
            //used to represent client screen size
            Rectangle clientScreenDim = null;
            //Used to read screenshots and client screen dimension
            ObjectInputStream ois = null;
            //start drawing GUI
            drawGUI();
    
            try{
                //Read client screen dimension
                ois = new ObjectInputStream(cSocket.getInputStream());
                clientScreenDim =(Rectangle) ois.readObject();
            }catch(IOException ex){
                ex.printStackTrace();
            }catch(ClassNotFoundException ex){
                ex.printStackTrace();
            }
            //Start recieveing screenshots
            new ClientScreenReciever(ois,cPanel);
            //Start sending events to the client
            new ClientCommandsSender(cSocket,cPanel,clientScreenDim);
            
        }
     
    }
    what i have to do Mr.Tolls..,
    - Raj

  9. #29
    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

    What you need to do is take ownership of your problem again and research what you've been told.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #30
    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

    I unable to control my inner JInternalFrame calling by JApplet. But in JFrame i can control it, thats why i choose the alternative JSP for run it..,
    - Raj

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

    Default Re: execute Java class from jsp page making problem

    Quote Originally Posted by gimbal2 View Post
    Or webstart, probably the only real goal here is to run a java application on the client, it doesn't have to be -in- the browser.
    You expected me to actually read the rest of the JSP code?
    :)

    I saw JSP. I saw an attempt to show a JFrame in the JSP...the rest (as they say) is history!

    But, yes. If this is simply an application, then web start would probably be the better option.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #32
    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 Mr.Tolls!

    I don't know idea about "web start", But i can learn 1st and will coding it..,

    Thank You..,

    Have A Happy Day..,
    - Raj

  13. #33
    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

    I Have A Doubt with using the web start,

    Is the web start suitable for Remote server client application?..,

    Guide me please..,
    - Raj

  14. #34
    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

    Can Anyone Replay me please..,

    Is the web start suitable for Remote server client application?..,

    even if i launch by browser how can i access the remote system without the server ip, i don't have idea , guide me please..,
    Last edited by raj.mscking@gmail.com; 04-15-2014 at 06:25 PM.
    - Raj

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

    Default Re: execute Java class from jsp page making problem

    Why do you think it won't be suitable?
    It's at least as suitable as an applet...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  16. #36
    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 Mr.Tolls!

    I try now itself and will back with successful result..,

    Have A Happy Day..,
    - Raj

Page 2 of 2 FirstFirst 12

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
  •