Results 1 to 8 of 8

Thread: Java Help

  1. #1
    king-waffles is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default Java Help

    Hi guys,

    I have made this application in java, basically an inventory system.I have a client that accesses the system, for mobile devices I have created a java servlet running within net beans.

    The problem I am having is that my mobile devices iPhone and android can't seem to load the servlet web page, but PCs have no problem loading it at all. Anyone got any ideas why this could be happening?

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

    Default

    What happens when your phones access the page?

  3. #3
    king-waffles is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    The server starts talking to the phone, but then it just stops and the phone comes up with page not found. If I got to a PC and use the same address, the page comes up fine.

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

    Default

    So what happens on the server?
    You should be able to debug through what's going on in the servlet (presumably)?

  5. #5
    king-waffles is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    Hi the server generates info when clients connect, first code snippet is what happens when a normal PC browser connects, second is what happens what a smart phone/mobile device connects. The smart phones / mobile devices are the ones with the problem. Note that i'm just accessing it using a web browser and it's nothing special just html.

    PC Connects
    Java Code:
    =======================================================
                                            STARTING THREAD #1...
    =======================================================
    
    Client connected :   /192.168.100.105
    Port :                          3276
    
    
    
    THREAD #1    -   MESSAGE : GET
    
    THREAD #1    -   MESSAGE : /servlet/stock
    
    THREAD #1    -   MESSAGE : HTTP/1.1
    THREAD #1    -   MESSAGE : GET
    
    LoopLimit = 299.0
    0 Compaq Presario CQ56 111SA Laptop 12 349 99
    1 Asus X52F EX469V Laptop 18 329 99
    2 Sony Vaio EA3S1E Laptop 5 589 99
    3 Samsung SyncMaster P2450H Monitor 33 179 99
    4 Philips Brilliance C line 226C2SB Monitor 28 109 99
    5 Dell Professional P2411H Monitor 26 214 99
    6 Kingston 64GB SSDNOW V100 SSD 4 79 99
    7 Corsair 60GB Force SSD 13 89 99
    8 OCZ 960GB IBIS SSD 1 2099 99
    9 Antec Dark Fleet DF 85 Case 21 120 00
    10 Antec One Hundred Case 44 44 99
    11 MSI nVidia GTX580 Graphics Card 9 329 99
    12 nVidia Geforce 3D Vision Kit PC Accessories 5 119 99
    
    THREAD #1    -   MESSAGE : Host:
    
    THREAD #1    -   MESSAGE : 192.168.100.105:5050
    THREAD #1    -   MESSAGE : Host:
    
    
    THREAD #1    -   MESSAGE : User-Agent:
    
    THREAD #1    -   MESSAGE : Mozilla/5.0
    
    THREAD #1    -   MESSAGE : (Windows;
    
    THREAD #1    -   MESSAGE : U;
    
    THREAD #1    -   MESSAGE : Windows
    
    THREAD #1    -   MESSAGE : NT
    
    THREAD #1    -   MESSAGE : 6.1;
    
    THREAD #1    -   MESSAGE : en-GB;
    
    THREAD #1    -   MESSAGE : rv:1.9.2.13)
    
    THREAD #1    -   MESSAGE : Gecko/20101203
    
    THREAD #1    -   MESSAGE : Firefox/3.6.13
    
    THREAD #1    -   MESSAGE : GTB7.1
    THREAD #1    -   MESSAGE : User-Agent:
    
    
    THREAD #1    -   MESSAGE : Accept:
    
    THREAD #1    -   MESSAGE : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    THREAD #1    -   MESSAGE : Accept:
    
    
    THREAD #1    -   MESSAGE : Accept-Language:
    
    THREAD #1    -   MESSAGE : en-gb,en;q=0.5
    THREAD #1    -   MESSAGE : Accept-Language:
    
    
    THREAD #1    -   MESSAGE : Accept-Encoding:
    
    THREAD #1    -   MESSAGE : gzip,deflate
    THREAD #1    -   MESSAGE : Accept-Encoding:
    
    
    THREAD #1    -   MESSAGE : Accept-Charset:
    
    THREAD #1    -   MESSAGE : ISO-8859-1,utf-8;q=0.7,*;q=0.7
    THREAD #1    -   MESSAGE : Accept-Charset:
    
    
    THREAD #1    -   MESSAGE : Keep-Alive:
    
    THREAD #1    -   MESSAGE : 115
    THREAD #1    -   MESSAGE : Keep-Alive:
    
    
    THREAD #1    -   MESSAGE : Connection:
    
    THREAD #1    -   MESSAGE : keep-alive
    THREAD #1    -   MESSAGE : Connection:
    
    =======================================================
                                               THREAD #1 CLOSED...
    =======================================================
    
    
    =======================================================
                                            STARTING THREAD #2...
    =======================================================
    
    Client connected :   /192.168.100.105
    Port :                          3278
    
    
    
    THREAD #2    -   MESSAGE : GET
    
    THREAD #2    -   MESSAGE : /favicon.ico
    
    THREAD #2    -   MESSAGE : HTTP/1.1
    THREAD #2    -   MESSAGE : GET
    
    
    THREAD #2    -   MESSAGE : Host:
    
    THREAD #2    -   MESSAGE : 192.168.100.105:5050
    THREAD #2    -   MESSAGE : Host:
    
    
    THREAD #2    -   MESSAGE : User-Agent:
    
    THREAD #2    -   MESSAGE : Mozilla/5.0
    
    THREAD #2    -   MESSAGE : (Windows;
    
    THREAD #2    -   MESSAGE : U;
    
    THREAD #2    -   MESSAGE : Windows
    
    THREAD #2    -   MESSAGE : NT
    
    THREAD #2    -   MESSAGE : 6.1;
    
    THREAD #2    -   MESSAGE : en-GB;
    
    THREAD #2    -   MESSAGE : rv:1.9.2.13)
    
    THREAD #2    -   MESSAGE : Gecko/20101203
    
    THREAD #2    -   MESSAGE : Firefox/3.6.13
    
    THREAD #2    -   MESSAGE : GTB7.1
    THREAD #2    -   MESSAGE : User-Agent:
    
    
    THREAD #2    -   MESSAGE : Accept:
    
    THREAD #2    -   MESSAGE : image/png,image/*;q=0.8,*/*;q=0.5
    THREAD #2    -   MESSAGE : Accept:
    
    
    THREAD #2    -   MESSAGE : Accept-Language:
    
    THREAD #2    -   MESSAGE : en-gb,en;q=0.5
    THREAD #2    -   MESSAGE : Accept-Language:
    
    
    THREAD #2    -   MESSAGE : Accept-Encoding:
    
    THREAD #2    -   MESSAGE : gzip,deflate
    THREAD #2    -   MESSAGE : Accept-Encoding:
    
    
    THREAD #2    -   MESSAGE : Accept-Charset:
    
    THREAD #2    -   MESSAGE : ISO-8859-1,utf-8;q=0.7,*;q=0.7
    THREAD #2    -   MESSAGE : Accept-Charset:
    
    
    THREAD #2    -   MESSAGE : Keep-Alive:
    
    THREAD #2    -   MESSAGE : 115
    THREAD #2    -   MESSAGE : Keep-Alive:
    
    
    THREAD #2    -   MESSAGE : Connection:
    
    THREAD #2    -   MESSAGE : keep-alive
    THREAD #2    -   MESSAGE : Connection:
    
    =======================================================
                                               THREAD #2 CLOSED...
    =======================================================
    
    
    =======================================================
                                            STARTING THREAD #3...
    =======================================================
    
    Client connected :   /192.168.100.105
    Port :                          3280
    
    
    
    THREAD #3    -   MESSAGE : GET
    
    THREAD #3    -   MESSAGE : /favicon.ico
    
    THREAD #3    -   MESSAGE : HTTP/1.1
    THREAD #3    -   MESSAGE : GET
    
    
    THREAD #3    -   MESSAGE : Host:
    
    THREAD #3    -   MESSAGE : 192.168.100.105:5050
    THREAD #3    -   MESSAGE : Host:
    
    
    THREAD #3    -   MESSAGE : User-Agent:
    
    THREAD #3    -   MESSAGE : Mozilla/5.0
    
    THREAD #3    -   MESSAGE : (Windows;
    
    THREAD #3    -   MESSAGE : U;
    
    THREAD #3    -   MESSAGE : Windows
    
    THREAD #3    -   MESSAGE : NT
    
    THREAD #3    -   MESSAGE : 6.1;
    
    THREAD #3    -   MESSAGE : en-GB;
    
    THREAD #3    -   MESSAGE : rv:1.9.2.13)
    
    THREAD #3    -   MESSAGE : Gecko/20101203
    
    THREAD #3    -   MESSAGE : Firefox/3.6.13
    
    THREAD #3    -   MESSAGE : GTB7.1
    THREAD #3    -   MESSAGE : User-Agent:
    
    
    THREAD #3    -   MESSAGE : Accept:
    
    THREAD #3    -   MESSAGE : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    THREAD #3    -   MESSAGE : Accept:
    
    
    THREAD #3    -   MESSAGE : Accept-Language:
    
    THREAD #3    -   MESSAGE : en-gb,en;q=0.5
    THREAD #3    -   MESSAGE : Accept-Language:
    
    
    THREAD #3    -   MESSAGE : Accept-Encoding:
    
    THREAD #3    -   MESSAGE : gzip,deflate
    THREAD #3    -   MESSAGE : Accept-Encoding:
    
    
    THREAD #3    -   MESSAGE : Accept-Charset:
    
    THREAD #3    -   MESSAGE : ISO-8859-1,utf-8;q=0.7,*;q=0.7
    THREAD #3    -   MESSAGE : Accept-Charset:
    
    
    THREAD #3    -   MESSAGE : Keep-Alive:
    
    THREAD #3    -   MESSAGE : 115
    THREAD #3    -   MESSAGE : Keep-Alive:
    
    
    THREAD #3    -   MESSAGE : Connection:
    
    THREAD #3    -   MESSAGE : keep-alive
    THREAD #3    -   MESSAGE : Connection:
    
    =======================================================
                                               THREAD #3 CLOSED...
    =======================================================
    
    
    =======================================================
                                            STARTING THREAD #4...
    =======================================================
    
    Client connected :   /192.168.100.105
    Port :                          3282
    
    
    
    THREAD #4    -   MESSAGE : GET
    
    THREAD #4    -   MESSAGE : /favicon.ico
    
    THREAD #4    -   MESSAGE : HTTP/1.1
    THREAD #4    -   MESSAGE : GET
    
    
    THREAD #4    -   MESSAGE : Host:
    
    THREAD #4    -   MESSAGE : 192.168.100.105:5050
    THREAD #4    -   MESSAGE : Host:
    
    
    THREAD #4    -   MESSAGE : User-Agent:
    
    THREAD #4    -   MESSAGE : Mozilla/5.0
    
    THREAD #4    -   MESSAGE : (Windows;
    
    THREAD #4    -   MESSAGE : U;
    
    THREAD #4    -   MESSAGE : Windows
    
    THREAD #4    -   MESSAGE : NT
    
    THREAD #4    -   MESSAGE : 6.1;
    
    THREAD #4    -   MESSAGE : en-GB;
    
    THREAD #4    -   MESSAGE : rv:1.9.2.13)
    
    THREAD #4    -   MESSAGE : Gecko/20101203
    
    THREAD #4    -   MESSAGE : Firefox/3.6.13
    
    THREAD #4    -   MESSAGE : GTB7.1
    THREAD #4    -   MESSAGE : User-Agent:
    
    
    THREAD #4    -   MESSAGE : Accept:
    
    THREAD #4    -   MESSAGE : text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    THREAD #4    -   MESSAGE : Accept:
    
    
    THREAD #4    -   MESSAGE : Accept-Language:
    
    THREAD #4    -   MESSAGE : en-gb,en;q=0.5
    THREAD #4    -   MESSAGE : Accept-Language:
    
    
    THREAD #4    -   MESSAGE : Accept-Encoding:
    
    THREAD #4    -   MESSAGE : gzip,deflate
    THREAD #4    -   MESSAGE : Accept-Encoding:
    
    
    THREAD #4    -   MESSAGE : Accept-Charset:
    
    THREAD #4    -   MESSAGE : ISO-8859-1,utf-8;q=0.7,*;q=0.7
    THREAD #4    -   MESSAGE : Accept-Charset:
    
    
    THREAD #4    -   MESSAGE : Keep-Alive:
    
    THREAD #4    -   MESSAGE : 115
    THREAD #4    -   MESSAGE : Keep-Alive:
    
    
    THREAD #4    -   MESSAGE : Connection:
    
    THREAD #4    -   MESSAGE : keep-alive
    THREAD #4    -   MESSAGE : Connection:
    
    =======================================================
                                               THREAD #4 CLOSED...
    =======================================================



    Smartphone Results ( not working )
    Java Code:
    =======================================================
                                            STARTING THREAD #1...
    =======================================================
    
    Client connected :   /192.168.100.100
    Port :                          56647
    
    
    
    THREAD #1    -   MESSAGE : GET
    
    THREAD #1    -   MESSAGE : /servlet/stock
    
    THREAD #1    -   MESSAGE : HTTP/1.1
    THREAD #1    -   MESSAGE : GET
    
    LoopLimit = 299.0
    0 Compaq Presario CQ56 111SA Laptop 12 349 99
    1 Asus X52F EX469V Laptop 18 329 99
    2 Sony Vaio EA3S1E Laptop 5 589 99
    3 Samsung SyncMaster P2450H Monitor 33 179 99
    4 Philips Brilliance C line 226C2SB Monitor 28 109 99
    5 Dell Professional P2411H Monitor 26 214 99
    6 Kingston 64GB SSDNOW V100 SSD 4 79 99
    7 Corsair 60GB Force SSD 13 89 99
    8 OCZ 960GB IBIS SSD 1 2099 99
    9 Antec Dark Fleet DF 85 Case 21 120 00
    10 Antec One Hundred Case 44 44 99
    11 MSI nVidia GTX580 Graphics Card 9 329 99
    12 nVidia Geforce 3D Vision Kit PC Accessories 5 119 99
    
    THREAD #1    -   MESSAGE : Host:
    
    THREAD #1    -   MESSAGE : 192.168.100.105:5050
    THREAD #1    -   MESSAGE : Host:
    
    
    THREAD #1    -   MESSAGE : User-Agent:
    
    THREAD #1    -   MESSAGE : Mozilla/5.0
    
    THREAD #1    -   MESSAGE : (iPhone;
    
    THREAD #1    -   MESSAGE : U;
    
    THREAD #1    -   MESSAGE : CPU
    
    THREAD #1    -   MESSAGE : iPhone
    
    THREAD #1    -   MESSAGE : OS
    
    THREAD #1    -   MESSAGE : 4_2_1
    
    THREAD #1    -   MESSAGE : like
    
    THREAD #1    -   MESSAGE : Mac
    
    THREAD #1    -   MESSAGE : OS
    
    THREAD #1    -   MESSAGE : X;
    
    THREAD #1    -   MESSAGE : en-us)
    
    THREAD #1    -   MESSAGE : AppleWebKit/533.17.9
    
    THREAD #1    -   MESSAGE : (KHTML,
    
    THREAD #1    -   MESSAGE : like

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

    Default

    And how does that help us here?

  7. #7
    king-waffles is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    Sorry the above post was just trying to show you where it was hanging. I get no errors while debuging. I will post my code below see if you can catch the problem, because I have been through this thing so many times and to me it seems solid.

    Java Code:
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    
    public class tcpServer extends JFrame implements  ActionListener {
        private int port = 5050   , trdCnt = 0 ;
        private double sleepTime = 0 ;
        private boolean debug = true , loopCTL = true , loopCTL2 = true ;
        private boolean foundRec = true ;
        private String messageTokens[]  = new String[ 16 ] ,
                 addrRecord[][]  = {
                      {"Compaq Presario CQ56-111SA", "Laptop", "12", "349.99"},
                      {"Asus X52F-EX469V", "Laptop", "18", "329.99"},
                      {"Sony Vaio EA3S1E", "Laptop", "5", "589.99"},
                      {"Samsung SyncMaster P2450H", "Monitor", "33", "179.99"},
                      {"Philips Brilliance C-line 226C2SB", "Monitor", "28", "109.99"},
                      {"Dell Professional P2411H", "Monitor", "26", "214.99"},
                      {"Kingston 64GB SSDNOW V100", "SSD", "4", "79.99"},
                      {"Corsair 60GB Force", "SSD", "13", "89.99"},
                      {"OCZ 960GB IBIS", "SSD", "1", "2099.99"},
                      {"Antec Dark Fleet DF-85", "Case", "21", "120.00"},
                      {"Antec One Hundred", "Case", "44", "44.99"},
                      {"MSI nVidia GTX580", "Graphics Card", "9", "329.99"},
                      {"nVidia Geforce 3D-Vision Kit", "PC Accessories", "5", "119.99"}};
        private ServerSocket server_socket;
        //private BufferedReader input;
        private PrintWriter output;
        private Container c ;
        private JTextArea display ;
        private JButton cancel , send, exit;
        private JPanel buttonPanel ;
        private StringTokenizer tokens ;
        private Record data ;
        private File aFile ;
        private RandomAccessFile file ;
        private static String pData[] []  = new String [ 300 ] [ 9 ];
        private  double loopLimit = 0;
        private Thread thrd[] ;
    
        public  tcpServer() {
           super ( "Computer Hardware ltd - SERVERSIDE APPLICATION") ;
    
           setupThreads() ;
    
           setup() ;
    
           RunServer() ;
    
        }
        
    
        public  void setThreadcount( int a ) {
           trdCnt = a ;
        }
    
        public void setupThreads() {
    
          thrd = new Thread[ 15 ] ;
        }
    
        public  void setup() {
          c = getContentPane();
    
          /** create an address record object */
          data  = new Record() ;
    
          SetupMenu() ;
          SetupToolbar() ;
          SetupPanels() ;
          SetupArrays() ;
          SetupButtons() ;
          SetUpTextArea() ;
    
          InitRecord() ;
    
          setSize( 400, 400 );
          setLocation( 10, 20 ) ;
          show();
        }
    
       public void SetupMenu() {
       }
    
       public void SetupToolbar() {
       }
    
       public void SetupPanels() {
    
          buttonPanel = new JPanel() ;
          c.add( buttonPanel , BorderLayout.SOUTH) ;
       }
    
       public void SetupArrays() {
       }
    
       public  void SetUpTextArea() {
    
          display = new JTextArea();
          display.setEditable( false );
          addWindowListener( new WindowHandler( this ) );
          c.add( new JScrollPane( display ),
                   BorderLayout.CENTER );
       }
    
        public void SetupButtons()  {
    
          exit = new JButton( "Exit" );
          exit.setBackground( Color.gray ) ;
          exit.setForeground( Color.white ) ;
    
          buttonPanel.add( exit ) ;
    
          exit.addActionListener( this );
        }
    
        public void InitRecord() {
           aFile = new File( "stock.dat" ) ;
    
          try {
    
             if ( !aFile.exists() ) {
    
                file = new RandomAccessFile( "stock.dat", "rw" );
                for ( int ii = 0 ; ii < 300 ; ii++ ) {
                   if (ii < 13 ) {
                      data.setRecID( ii ) ;
                      data.setItemName( addrRecord[ ii ][ 0 ] ) ;
                      data.setDeviceType( addrRecord[ ii ][ 1 ] ) ;
                      data.setCurrentStock( addrRecord[ ii ][ 2 ] ) ;
                      data.setPrice( addrRecord[ ii ][ 3 ] ) ;
                   }
                   else {
                      data.setRecID(  ii ) ;
                      data.setItemName( " " ) ;
                      data.setDeviceType( " " ) ;
                      data.setCurrentStock( " " ) ;
                      data.setPrice( " " ) ;
    
                   }
    
                   file.seek( ii * data.getSize() );
                   data.write( file );
    
                   display.append("\nRecords have been written :  " +
                        data.getRecID()  + " " +
                        data.getItemName()  + " " +
                        data.getDeviceType()  + " " +
                        data.getCurrentStock()  + " " +
                        data.getPrice() ) ;
    
                }
             }
             else {
                file = new RandomAccessFile( "stock.dat", "rw" );
             }
    
             file.close();
    
          }
          catch ( IOException e ) {
                System.err.println( e.toString() );
                System.exit( 1 );
          }
    
        }
    
        public void RunServer() {
           int i3 = 0 ;
    
           try {
    
              server_socket = new ServerSocket( 5050, 100,
                                      InetAddress.getLocalHost());
              display.setText("=======================================================\n" );
              display.append ("               Computer Hardware ltd - SERVERSIDE APPLICATION"     );
              display.append ("\n=======================================================\n");
              display.append("\nHosted on :               " + InetAddress.getLocalHost());
              display.append(" \nPort :                           " + server_socket.getLocalPort());
    
              while( loopCTL  ) {
                 Socket socket = server_socket.accept();
                 display.append("\n\n=======================================================\n" );
                 display.append ("                                        STARTING THREAD #" + (trdCnt+1) + "..."   );
                 display.append ("\n=======================================================\n");
                 display.append("\nClient connected :   " + socket.getInetAddress());
                 display.append("\nPort :                          " + socket.getPort() + "\n\n");
    
                 try {
                    MyThread request =
                                  new MyThread( this , socket , trdCnt );
                    thrd[ trdCnt ]  = request ;
    
                    thrd[ trdCnt ].start() ;
                    trdCnt++ ;
                 }
                 catch(Exception e) {
    	        sysPrint( "" + e);
                 }
              }
           }
           catch (IOException e) {
              display.append("\n" + e);
           }
        }
    
       public void actionPerformed( ActionEvent e )    {
          if ( e.getSource() == exit )
             sysExit( 0 ) ;
       }
    
       public  void closeConnection() {
          try {
             server_socket.close();
          }
          catch (IOException e) {
             display.append("\n" + e);
          }
       }
    
       public void sysExit( int ext ) {
          loopCTL  = false ;
          loopCTL2 = false ;
          int thrdLen = thrd.length ;
          closeConnection() ;
          for( int iii = 0 ; iii < thrdLen ; iii++ ) {
             thrd[ iii ] = null ;
          }
          System.exit( ext ) ;
       }
    
       public void sysPrint( String str ) {
          if( debug ) {
             System.out.println("" + str ) ;
          }
       }
    
       public static void main(String args[]) {
           final tcpServer server = new tcpServer() ;
           server.addWindowListener(
             new WindowAdapter() {
                public void windowClosing( WindowEvent e )
                {
                   server.closeConnection() ;
                   System.exit( 0 );
    
                }
             }
          );
       }
    
    
    
    
       class WindowHandler extends WindowAdapter {
          tcpServer tcpS;
    
          public WindowHandler( tcpServer t ) { tcpS = t; }
    
          public void windowClosing( WindowEvent e ) { tcpS.sysExit( 0 ); }
       }
    
       public class MyThread extends Thread {
          private Socket socket;
          private BufferedReader input2;
          private PrintWriter output2;
          private PrintWriter outp ;
          private int trdCnt , ar , numEntries = 0 ;
          private tcpServer tcpS ;
          private String getStock = "/servlet/stock" ;
    
          /** *********************************************************
           * The purpose of the MyThread() constructor is to used the
           * passed parameters to initialize MyThread class level
           * variables.
           **************************************************************/
          public MyThread( tcpServer tps , Socket soc_ket , int trd_Cnt  ) throws Exception {
             trdCnt =  trd_Cnt ;
             tcpS = tps ;
             socket  = soc_ket;
             this.input2  = new BufferedReader(new InputStreamReader(soc_ket.getInputStream()));
             this.output2 = new PrintWriter(soc_ket.getOutputStream(),true);
          }
    
          /** *********************************************************
           * The run() method responds to the client's request.
           **************************************************************/
           public void run() {
             int IndexOfEquals = 0 , i3 = 0 , ii = 0 , recLength = addrRecord.length ;
             String strName = "" ;
    
             sysPrint( "STARTING THREAD #" + (trdCnt+1) + "..." ) ;
             String message = "" ;
    
                      // print received data
             try {   // try #1
                while( !message.toUpperCase().equals( "QUIT" )) {
                   message = (String)input2.readLine();
                   tokens = new StringTokenizer( message ) ;
    
                   if ( tokens.countTokens() >= 1 )   {
                      int iii = 0 ;
                      while( tokens.hasMoreTokens() )  {
                         messageTokens[ iii ] = tokens.nextToken().toString() ;
                         display.append("\n\nTHREAD #" + (trdCnt+1) + "    -   MESSAGE : " + messageTokens[ iii ] ) ;
                         iii++ ;
                      }
    
                      display.append("\nTHREAD #" + (trdCnt+1) + "    -   MESSAGE : " + messageTokens[ 0 ] + "\n") ;
                      sysPrint( "THREAD #" + (trdCnt+1) + "    -   MESSAGE : " + messageTokens[ 0 ] ) ;
                      sysPrint( "THREAD #" + (trdCnt+1) + "    -   MESSAGE : " + messageTokens[ 1 ] ) ;
    
                      if( messageTokens[ 1 ].equals( getStock ) ) {
                            sysPrint( "THREAD #" + (trdCnt+1) + "    -   SERVLET" ) ;
                            String servName = "http://192.168.100.105:5050/servlet/stock" ;
    
                             // create and send HTML page to client
                            StringBuffer buf = new StringBuffer();
                            buf.append( "<HTML><HEAD><TITLE>" );
                            buf.append( "Computer Hard ltd - SERVLET ACCESS" );
                            buf.append( "</TITLE></HEAD><BODY>\n" );
                            buf.append( "<FORM METHOD=\"GET\" ACTION=GET" );
    
                            buf.append( "<p><b><font size=5>Computer Hardware ltd - SERVLET ACCESS</p>" );
                            buf.append( "<p><b><font size=5>ITEM BROWSER</p></b>" );
                            buf.append( "<p>Select an item from the dropdown menu... <br><br>  <select name=\"getaName\">" );
    
                            listNames( 0 ) ;
                            //ar = pData.length ;
    
                            for ( ii = 0 ; ii < numEntries+1 ; ii++ ) {
                               buf.append( "<option value=\"" + pData[ ii ][ 2 ] + "\">" +
                                      " " + pData[ ii ][ 2 ] + "</option>" ) ;
                               sysPrint("<option value=\"" + pData[ ii ][ 1 ] + "\">" +
                                       pData[ ii ][ 2 ] + "</option>" ) ;
                               sysPrint( "Thread run() 6: The value of ii is " + ii ) ;
                            }
                            buf.append( "</select><br><br><br>" ) ;
                            buf.append( "<p>Press the button to retrieve information on an item... <br><br><input type=\"submit\" value=\"Get Name\">" ) ;
                            buf.append( "</FORM>" ) ;
                            buf.append( "</font></BODY></HTML>" );
                            output2.println( buf.toString() );
                      }
                      else if ( messageTokens[ 0 ].toUpperCase().equals( "GET" ) ) {
                            sysPrint("Thread" + (trdCnt+1) + " run() 8b: messageTokens[ 0 ] equals GET." ) ;
                            sysPrint("Thread" + (trdCnt+1) + " run() 8c: messageTokens[ 1 ] is  " + messageTokens[ 1 ] ) ;
                            if ( messageTokens[ 1 ].substring(0 , 4).equals( "/ser" ) ) {
                               IndexOfEquals = messageTokens[ 1 ].lastIndexOf('=') ;
                               strName = "" + messageTokens[ 1 ].substring( IndexOfEquals+1 ,
                                         messageTokens[ 1 ].length() ) ;
                               sysPrint("Thread" + (trdCnt+1) + " run() 8d: " + strName + " IndexOfEquals " + IndexOfEquals) ;
    
                               if ( IndexOfEquals > 0 )  {
                                  sysPrint("Thread" + (trdCnt+1) + " run() 9: " + strName ) ;
    
                                  ii = 0  ;
                                  StringBuffer buf = new StringBuffer();
    
                                  listNames( 0 ) ;
    
                                  /** **************************************************
                                   *  The while logic below has to be changed to look in
                                   *  the randomaccessfile for  the name
                                   *****************************************************/
    
                                  while ( ii < recLength ) {
                                     if ( pData[ ii ][ 2 ].toUpperCase().equals( strName.toUpperCase() ) ) {
                                        sysPrint("Thread" + (trdCnt+1) + " run() 8cc: Found record " + strName ) ;
                                        display.append("\n" + "RecordFound" ) ;
                                        buf.append( "<HTML><HEAD><TITLE>" );
                                        buf.append( "Computer Hardware ltd - SERVLET ACCESS - ITEM DETAILS" );
                                        buf.append( "</TITLE></HEAD><BODY>\n" );
                                        buf.append( "" + pData[ ii ][ 1 ] + "<br>" ) ;
                                        buf.append( "" + pData[ ii ][ 2 ] + "<br>" ) ;
                                        buf.append( "" + pData[ ii ][ 3 ] + "<br>" ) ;
                                        buf.append( "" + pData[ ii ][ 4 ] + "<br>" ) ;
                                        buf.append( "</BODY></HTML>" );
                                        output2.println( buf.toString() );
                                        sysPrint("Thread" + (trdCnt+1) + " run() 8cd: Found record " + buf.toString() ) ;
                                        ii =  recLength = 10 ;
                                        break ;
                                     }
    
                                     ii++ ;
                                  }  // End of while loop
    
                               }  // End of outer if
                            }
                      }
                      else if ( messageTokens[ 0 ].toUpperCase().equals( "FIND" ) ) {
                             ; //findName() ;
                      }
                      else if ( messageTokens[ 0 ].toUpperCase().equals( "LISTALL" )
                         ||  messageTokens[ 0 ].toUpperCase().equals( "REFRESH" ) ) {
                           
                            synchronized( MyThread.this ) {
                               listNames( 1 ) ;
                               MyThread.this.yield() ;
                            } // End of synchronized block
                      }
                      else if ( messageTokens[ 0 ].toUpperCase().equals( "ADD;;" ) ) {
                           
                            synchronized( MyThread.this ) {
                               addName( message ) ;
                               MyThread.this.yield() ;
                            } // End of synchronized block
                      }
                      else if ( messageTokens[ 0 ].toUpperCase().equals( "UPDATE;;" ) ) {
                            
                            synchronized( MyThread.this ) {
                               updateName( message ) ;
                               MyThread.this.yield() ;
                            } // End of synchronized block
                      }
                      else if ( messageTokens[ 0 ].toUpperCase().equals( "DELETE;;" ) ) {
    
                            synchronized( MyThread.this ) {
                               deleteName() ;
                               MyThread.this.yield() ;
                            } // End of synchronized block
                      }
                      iii = 0 ;
                   }
                   else  {
                         display.append( message );
                         //message = null; //so the loop will terminate the server
                         break;
                      }  /** End of if-else */
                } /** End of while */
                //sendData ( "FROM SERVER==> QUIT" ) ;
             }                                  // End of try #1
             catch (IOException e) {
                   display.append("\n" + e);
             }                                  // End of try/catch #2
    
             // connection closed by client
             try {   // try #2
                   socket.close();
                   display.append("\n=======================================================\n" );
                   display.append ("                                           THREAD #" + (trdCnt+1) + " CLOSED..."   );
                   display.append ("\n=======================================================\n");
                   thrd[ trdCnt ]  = null ;
             }
             catch (IOException e) {
                   display.append("\n" + e);
             }                            // End of try/catch #2
          }
          /***************** End of run() method *****************************/
    
          /** *****************************************************************************
           * The addName() this method adds a name using the RandomAccessFile API and
           * the record ID.
           ***************************************************************************** */
          public void addName( String message ) {
    
             int ii = 0 ;
    
             
             tokens = new StringTokenizer( message, ";;" ) ;
    
             if ( tokens.countTokens() >= 1 )   {
    
                while( tokens.hasMoreTokens() )  {
                   messageTokens[ ii ] = tokens.nextToken().trim().toString() ;
                   display.append("\n" + messageTokens[ ii ] ) ;
                   ii++ ;
                }
             }
    
             display.append( "\nThe size of the recID is " +
                          messageTokens[ 1 ].length() );
             data.setRecID( Integer.parseInt( messageTokens[ 1 ].trim() ) ) ;
             data.setItemName( messageTokens[ 2 ] ) ;
             data.setDeviceType( messageTokens[ 3 ] )  ;
             data.setCurrentStock(  messageTokens[ 4 ] )  ;
             data.setPrice( messageTokens[ 5 ] ) ;
    
             try {
                file = new RandomAccessFile( "stock.dat", "rw" );
                file.seek(  0  * data.getSize() );
                file.seek(  Integer.parseInt( messageTokens[ 1 ] ) * data.getSize() );
                data.write( file );
                file.close();
             }
             catch (IOException e) {
                display.append("\n" + e);
             }
    
             display.append( "\nThread #" + (trdCnt+1) + " The item to be updated is : " +
                  data.getRecID()   + " " +
                  data.getItemName(  ) + " " +
                  data.getDeviceType(  ) + " " +
                  data.getCurrentStock(  )  + " " +
                  data.getPrice( )) ;
           }
    
           /** *****************************************************************************
            * The listNames() method is used to gather all of the records in the address.dat
            * file and send this data back to the client.
            ***************************************************************************** */
           public void listNames( int reason ) {
               int ii = 0 , recLength = addrRecord.length, iii = 0  ;
               data = new Record();
               String str = "" ;
    
               foundRec =  false ;
    
               try {
               /** Divide  the length of the file by the record size to
                *  determine the number of records in the file
                */
                file = new RandomAccessFile( "stock.dat", "rw" );
                loopLimit = file.length() / data.getSize() ;
    
                display.append( "\nLoopLimit = " + loopLimit ) ;
    
                if( reason == 1 ) {
                   sendData ( "ListAll;;" ) ;
                   sysPrint("Thread" + (trdCnt+1) + "ListAll;; message sent") ;
                }
    
                ii = 0 ;
    
                while ( ii <  ( (int)loopLimit )  ) {
                   //file.seek( ( 0 ) * data.getSize() );
                   file.seek( ( ii ) * data.getSize() );
                   data.ReadRec( file );
    
                   if ( ( data.getRecID() >= 0 ) && ( data.getRecID() < 300 )
                            && !data.getItemName().equals( "" )  ) {
    
                      display.append( "\n" + data.getRecID() + " " +
                                 data.getItemName().trim() + " " +
                                 data.getDeviceType().trim()  + " " +
                                 data.getCurrentStock().trim() + " " +
                                 data.getPrice().trim()) ;
    
                      pData[ iii ] [ 0 ]  =  String.valueOf( data.getRecID() ) ;
                      pData[ iii ] [ 1 ]  =  data.getItemName().trim()  ;
                      pData[ iii ] [ 2 ]  =  data.getDeviceType().trim()  ;
                      pData[ iii ] [ 3 ]  =  data.getCurrentStock().trim()  ;
                      pData[ iii ] [ 4 ]  =  data.getPrice().trim()  ;
    
                      str =  "" + ( pData[ iii ] [ 0 ]).trim()
                              + ";; " + ( pData[ iii ] [ 1 ]).trim()
                              + ";; " + ( pData[ iii ] [ 2 ]).trim()
                              + ";; " + ( pData[ iii ] [ 3 ]).trim()
                              + ";; " + ( pData[ iii ] [ 4 ]).trim()
                              + ";; " + ";;;";
    
                      if( reason == 1 ) {
                         sendData( str) ;
                         sysPrint("Thread" + (trdCnt+1) + " record sent was " + str ) ;
                      }
                     
                      iii++ ;
                   }
    
                   ii++ ;
                }
                numEntries = iii - 1 ;
    
                if( reason == 1 ) {
                   sendData ( "ListAllDone;;Thread" + (trdCnt+1) + ";;" ) ;
                   sendData ( "FILELENGTH;;" + (numEntries+1) + ";;") ;
                   sysPrint("Thread" + (trdCnt+1) + " ListAllDone;; sent. " ) ;
                }
    
                file.close() ;
             }
             catch ( IOException ex ) {
                   //part.setText( "Error reading file" );
             }
             if( reason == 1 ) {
                sendData( "GetAllDone;;Thread" + (trdCnt+1) + ";;"  ) ;
             }
          }
    
          /** ************************************************************
           * The sendData() method sends record data back to the client
           ***************************************************************/
          private void sendData( String str ) {
             if (str != null ) {
                output2.println( str );
             }
             else {
                output2.println( " " ) ;  // don't send nulls to client
                sysPrint( "/********************************************************" ) ;
                sysPrint( " * str =s Null .            "  ) ;
                sysPrint( "/********************************************************" ) ;
             }
             //output2.flush() ;
          }
    
          /** *****************************************************************************
           * The updateName() method updates a name using the RandomAccessFile API and
           * the record ID.
           ***************************************************************************** */
          public void updateName( String message ) {
    
             int ii = 0 ;
    
             display.append( "\nhread" + (trdCnt+1) + " Currrently in updateName() method." ) ;
             tokens = new StringTokenizer( message, ";;" ) ;
    
             if ( tokens.countTokens() >= 1 )   {
    
                while( tokens.hasMoreTokens() )  {
                   messageTokens[ ii ] = tokens.nextToken().trim().toString() ;
                   display.append("\n" + messageTokens[ ii ] ) ;
                   ii++ ;
                }
             }
    
             display.append( "\nThe size of the recID is " +
                             messageTokens[ 1 ].length() );
             data.setRecID( Integer.parseInt( messageTokens[ 1 ].trim() ) ) ;
             data.setItemName( messageTokens[ 2 ] ) ;
             data.setDeviceType( messageTokens[ 3 ] )  ;
             data.setCurrentStock(  messageTokens[ 4 ] )  ;
             data.setPrice( messageTokens[ 5 ] ) ;
    
             try {
                file = new RandomAccessFile( "stock.dat", "rw" );
                file.seek(  0  * data.getSize() );
                file.seek(  Integer.parseInt( messageTokens[ 1 ] ) * data.getSize() );
                data.write( file );
                file.close();
             }
             catch (IOException e) {
                display.append("\n" + e);
             }
    
             display.append( "\nhread" + (trdCnt+1) + " The record to be updated is " +
                data.getRecID()   + " " +
                data.getItemName(  ) + " " +
                data.getDeviceType(  ) + " " +
                data.getCurrentStock(  )  + " " +
                data.getPrice( )) ;
          }
    
          /** *****************************************************************************
           * The method deleteName() will use the record ID and the RandomAccessFile
           * API to delete a record in the file.
           ***************************************************************************** */
          public void deleteName() {
             int ii = 0 , recLength = addrRecord.length ;
    
             display.append( "\nThread" + (trdCnt+1) + " Currrently in deleteName() method." ) ;
    
             data.setItemName( " " ) ;
             data.setDeviceType( " " )  ;
             data.setCurrentStock(  " " )  ;
             data.setPrice( " " ) ;
             ii =  messageTokens[ 1 ].indexOf(";") ;
             messageTokens[ 1 ] = (messageTokens[ 1 ]).substring( 0 , ii ) ;
             data.setRecID( Integer.parseInt( messageTokens[ 1 ] ) ) ;
    
             try {
                file = new RandomAccessFile( "stock.dat", "rw" );
                file.seek(  0  * data.getSize() );
                file.seek(  Integer.parseInt( messageTokens[ 1 ] ) * data.getSize() );
                data.write( file );
                file.close();
             }
             catch (IOException e) {
                display.append("\n" + e);
             }
    
             display.append( "\nThread" + (trdCnt+1) + " The record to be deleted is " +
                data.getRecID()   + "1 " +
                data.getItemName(  ) + "2 " +
                data.getDeviceType(  ) + "3 " +
                data.getCurrentStock(  )  + "4 " +
                data.getPrice( ));
          }
          /***************** End of deleteName() method *****************************/
    
    
         /** *****************************************************************************
          * The findName() this method finds a name using the RandomAccessFile API and
          * the record ID.
          ***************************************************************************** */
         public void findName( String message ) {
    
         }
    
    
       }
       /***************** End of MyThread Class *****************************/
    
       /** ***********************************************************************
        *  The Record class manages the Address.dat file. This file contains the
        *  address records that the user wants to maintain. The methods in this class
        *  are:
        *   1- fill ()
        *   2- getAddress()
        *   3- getCity()
        *   4- getEmail()
        *   5- getFirstName()
        *   6- getLastName()
        *   7- getRecID()
        *   8- getSize()
        *   9- getState()
        *  10- getTelephone()
        *  11- getZip()
        *  12- ReadRec(
        *  13- setAddress()
        *  14- setCity()
        *  15- setEmail()
        *  16- setFirstName()
        *  17- setLastName()
        *  18- setRecID()
        *  19- setState()
        *  20- setTelephone()
        *  21- setZip()
        *  22- write()
        *
        *
        *
        * <p>Title: </p>
        * <p>Description: </p>
        * <p>Copyright: Copyright (c) 2006</p>
        * <p>Company: </p>
        * @author unascribed
        * @version 1.0
        ************************************************************************* */
       public class Record  {
          private int recID ;
          private String ItemName ;
          private String DeviceType ;
          private String CurrentStock ;
          private String Price ;
          private int ii = 0 ;
    
          /** ******************************************************************
           * ReadRec() reads a record from the specified RandomAccessFile.
           *  1- Reads an int for the recid
           *  2- Reads chars for the firstname field.
           *  3- Reads chars for the lastName field.
           *  4- Reads chars for the address field.
           *  5- Reads chars for the city field.
           *  6- Reads chars for the state field.
           *  7- Reads chars for the zip field.
           *  8- Reads chars for the telephone field.
           *  9- Reads chars for the email field.
           *
           ********************************************************** */
    
          public void ReadRec( RandomAccessFile file ) throws IOException
          //public synchronized void ReadRec( RandomAccessFile file ) throws IOException
          {
             char f[] = new char[ 45 ];
             StringTokenizer tokens ;
             StringBuffer buf1  = new StringBuffer("");
    
             recID = file.readInt();
    
             for ( int i = 0; i < f.length; i++ ) {
                f[ i ] = file.readChar();
                if ( !Character.isLetterOrDigit( f[ i ] ) )
                    f[ i ] = ' ' ;
             }
             ItemName = new String( f );
             ItemName = ItemName.trim() ;
    
             for ( int i = 0; i < f.length; i++ ) {
                f[ i ] = file.readChar();
                if ( !Character.isLetterOrDigit( f[ i ] ) )
                    f[ i ] = ' ' ;
             }
             DeviceType = new String( f );
             DeviceType = DeviceType.trim() ;
    
             for ( int i = 0; i < f.length; i++ ) {
                f[ i ] = file.readChar();
                if ( !Character.isLetterOrDigit( f[ i ] ) )
                    f[ i ] = ' ' ;
             }
             CurrentStock = new String( f );
             CurrentStock = CurrentStock.trim() ;
    
             for ( int i = 0; i < f.length; i++ ) {
                f[ i ] = file.readChar();
                if ( !Character.isLetterOrDigit( f[ i ] ) )
                    f[ i ] = ' ' ;
             }
             Price = new String( f );
             Price = Price.trim() ;
    
             for ( int i = 0; i < f.length; i++ ) {
                f[ i ] = file.readChar();
                if ( !Character.isLetterOrDigit( f[ i ] ) )
                    f[ i ] = ' ' ;
             }
             
             for ( int i = 0; i < f.length; i++ ) {
                f[ i ] = file.readChar();
                if ( !Character.isLetterOrDigit( f[ i ] ) )
                    f[ i ] = ' ' ;
             }
    
             for ( int i = 0; i < f.length; i++ ) {
                f[ i ] = file.readChar();
                if ( !Character.isLetterOrDigit( f[ i ] ) )
                     if ( f[ i ] != '-' || f[ i ] != '@'  )
                        ;
                     else
                        f[ i ] = ' ' ;
             }
    
             for ( int i = 0; i < f.length; i++ ) {
                f[ i ] = file.readChar();
                if ( !Character.isLetterOrDigit( f[ i ] ) )
                   if ( f[ i ] == '-' || f[ i ] == '@' || f[ i ] == '.'  )
                        ;
                     else
                        f[ i ] = ' ' ;
             }
            
             //notifyAll() ;
          }
    
          /** **************************************************************
           *  The fill method is used to fill in the passed string with
           *  blanks.
           *****************************************************************/
           public StringBuffer fill ( String str, StringBuffer buf ) {
              String strTwo = new String( "                     "  +
               "                                             " ) ;
    
             if ( str != null )
                buf = new StringBuffer( str + strTwo );
             else
                buf = new StringBuffer( strTwo );
    
             buf.setLength( 45 );
    
             return buf ;
          }
    
          /** ************************************************************
           *  Write a record to the specified RandomAccessFile file.
           ****************************************************************/
          //public synchronized void write( RandomAccessFile file ) throws IOException
          public void write( RandomAccessFile file ) throws IOException
          {
             StringBuffer buf  = new StringBuffer( " " );
             String str = "" ;
    
             file.writeInt( recID );
             str = "" + recID ;
    
             //System.out.println( "The value of quantity on write is "
              //              + quantity )
    
             buf = fill ( ItemName, buf ) ;
             file.writeChars( buf.toString() );
             str = str + buf ;
    
             buf = fill ( DeviceType, buf.delete(0, 44) ) ;
             file.writeChars( buf.toString() );
             str = str + buf ;
    
             buf = fill ( CurrentStock, buf.delete(0, 44) ) ;
             file.writeChars( buf.toString() );
             str = str + buf ;
    
             buf = fill ( Price, buf.delete(0, 44) ) ;
             file.writeChars( buf.toString() );
             str = str + buf ;
    
             sysPrint( "\nFrom write: the length of str is " + str.length()
                 + " and the string is " + str ) ;
    
             //notifyAll() ;
          }
    
    
          /** *****************************************************************************
           * The getRecID() method is used to obtain and return the record ID.
           ***************************************************************************** */
          public int getRecID() { return recID; }
    
          /** *****************************************************************************
           * The getFirstName() method is used to obtain and return the First Name.
           ***************************************************************************** */
          public String getItemName() { return ItemName.trim(); }
    
          /** *****************************************************************************
           * The getLastName() method is used to obtain and return the Last Name.
           ***************************************************************************** */
          public String getDeviceType() { return DeviceType.trim(); }
    
          /** *****************************************************************************
           * The getAddress() method is used to obtain and return the Address.
           ***************************************************************************** */
          public String getCurrentStock() { return CurrentStock.trim(); }
    
          /** *****************************************************************************
           * The getCity() method is used to obtain and return the City.
           ***************************************************************************** */
          public String getPrice() { return Price.trim(); }
         
          /** *****************************************************************************
           * The setFirstName() method is used to set the First Name field in this record.
           ***************************************************************************** */
          public void setItemName( String f ) { ItemName = f; }
    
          /** *****************************************************************************
           * The setLastName() method is used to set the Last Name field in this record.
           ***************************************************************************** */
          public void setDeviceType( String f ) { DeviceType = f; }
    
          /** *****************************************************************************
           * The setAddress() method is used to set the Address field in this record.
           ***************************************************************************** */
          public void setCurrentStock( String f ) { CurrentStock = f; }
    
          /** *****************************************************************************
           * The setCity() method is used to set the City field in this record.
           ***************************************************************************** */
          public void setPrice( String f ) { Price = f; }
    
          /** *****************************************************************************
           * The setRecID() method is used to set the RecID field in this record.
           ***************************************************************************** */
          public void setRecID( int q ) { recID = q; }
    
          public int getSize() { return 752; }
       }
    
    }

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

    Default

    You're going to have to find some better way of breaking this down, because there's no way I'm trawling through that lot.

    I have no idea what your message flow is, or which message it's failing on. You must be able to identify that and narrow it down.

    You say you have a servlet, yet I see no servlet there at all.

Posting Permissions

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