<APPLET CODE="search_book.class" WIDTH=515 HEIGHT=417></APPLET>

解决方案 »

  1.   

    要安装JAVA运行环境(JRE),这个跟JDK不是同一回事。然后可以在控制面板中进行设置!
      

  2.   

    我用appletviewer后显示的是一块黄色区域,上面说Invalid Params 0不知道是什么意思呢??
    是什么地方导致这样的错误呢??
      

  3.   

    控制台显示的具体错误信息如下:java.lang.NoClassDefFoundError: search_book (wrong name: book/search_book) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:539) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123) at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:157) at java.lang.ClassLoader.loadClass(ClassLoader.java:289) at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:123) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:561) at sun.applet.AppletPanel.createApplet(AppletPanel.java:617) at sun.plugin.AppletViewer.createApplet(Unknown Source) at sun.applet.AppletPanel.runLoader(AppletPanel.java:546) at sun.applet.AppletPanel.run(AppletPanel.java:298) at java.lang.Thread.run(Thread.java:534)java.lang.NoClassDefFoundError: search_book (wrong name: book/search_book) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:539) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123) at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:157) at java.lang.ClassLoader.loadClass(ClassLoader.java:289) at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:123) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:561) at sun.applet.AppletPanel.createApplet(AppletPanel.java:617) at sun.plugin.AppletViewer.createApplet(Unknown Source) at sun.applet.AppletPanel.runLoader(AppletPanel.java:546) at sun.applet.AppletPanel.run(AppletPanel.java:298) at java.lang.Thread.run(Thread.java:534)
    不知道到底是什么地方不对了,我确实都放在同、一目录下了!!!!!!!!!
      

  4.   

    我的applet如下:谢谢
    package book;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;import java.util.*;
    import java.io.*;
    import java.net.*;/**
     *  This applet allows a user to search books and get a list of
     *  books.  The applet communicates w/ a servlet which accesses a database.
     *
     *  Applet and servlet communication is outlined below:
     *
     *  <pre>
     *  To search the book list:
     *    1.  The applet sends a GET request to the servlet
     *    2.  The servlet replies w/ a serialized vector of Book objects
     *    3.  The results are displayed in the GUI list component.
     *  </pre>
     *
     *  @author Chad (shod) Darby,  [email protected]
     *  @version 0.9, 31 July 1998
     *
     */
    public class search_book extends Applet
    { private Panel toolBarPanel;
    private Button searchButton;
    private Panel statusBarPanel;
    private Label statusLabel;

    private TextArea statusTextArea;
       
        private String webServerStr = null;
        private String hostName = "localhost";
    private int port = 8080;
        private String servletPath = "myapp/Search_result";
         
    private final int COLUMN_WIDTH = 20;

    public void init()
    {
    this.setLayout(new BorderLayout());

    toolBarPanel = new Panel();
    toolBarPanel.setLayout(new FlowLayout());
    this.add(BorderLayout.NORTH, toolBarPanel); searchButton = new Button("search Books");
    toolBarPanel.add(searchButton); statusBarPanel = new Panel();
    statusBarPanel.setLayout(new FlowLayout());
    this.add(BorderLayout.SOUTH, statusBarPanel); statusLabel = new Label("Status Messages");
    statusBarPanel.add(statusLabel);        statusTextArea = new TextArea(3, 50);
            statusBarPanel.add(statusTextArea);

    // register listeners
    searchButton.addActionListener(new DisplayButtonActionListener());

            // get the host name and port of the applet's web server        
            URL hostURL = getCodeBase();
    hostName = hostURL.getHost();
            port = hostURL.getPort();

    if (port == -1)
    {
    port = 8080;
    }

            log("Web Server host name: " + hostName);
            
            webServerStr = "http://" + "localhost" + ":" + port + "/" + servletPath;
            log("Web String full = " + webServerStr);

    }


    /**
     *  Get a list of students.  
     *
     *  This is accomplished by connecting to the servlet using a GET.  The servlet
     *  will return a vector of student objects.
     *  
     */
    protected Vector getBookList()
    {        ObjectInputStream inputFromServlet = null;
            Vector bookVector = null;
            
        try
        {     
            // build a GET url string w/ encoded name/value pairs
            //
            // Send over UserOption=AppletDisplay.  The servlet will interpret
            // the user option and send back the student list as a serialized vector
            // of student objects.
            //
            String servletGET = webServerStr + "?" 
                                + URLEncoder.encode("UserOption") + "=" 
                                + URLEncoder.encode("AppletDisplay");
            
                // connect to the servlet
                log("Connecting...");
                URL Bookservlet = new URL( servletGET );
                URLConnection servletConnection = Bookservlet.openConnection();  
                 
            // Read the input from the servlet.  
            //
            // The servlet will return a serialized vector containing
            // student entries.
            //
    log("Getting input stream");
            inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());         bookVector = readBookVector(inputFromServlet);
            
        }
        catch (Exception e)
        {
            log(e.toString());
        }        return bookVector;
                
    }    /**
         * Read the input from the servlet.  <b>
         *
         * The servlet will return a serialized vector containing
         * student entries.
         *
         */
        protected Vector readBookVector(ObjectInputStream theInputFromServlet)
        {
            Vector theBookVector = null;
            
            try
            {         
                // read the serialized vector of students objects from
                // the servlet
                //
            log("Reading data...");
            theBookVector = (Vector) theInputFromServlet.readObject();
            log("Finished reading data.  " + theBookVector.size() + " Books returned");
            
            theInputFromServlet.close();
            }
            catch (IOException e)
            {
                log(e.toString());    
            }
            catch (ClassNotFoundException e)
            {
                log(e.toString());                
            }
            catch (Exception e)
    {
                System.out.println(e);                
    }

            return theBookVector;
        }
        
        /**
         * Display the list of books <br>
         *
         * Iterate over the vector of books and display
         * the name, e-mail and company in the multi-column list.
         */
        protected void displayBooks(Vector bookVector)
        {
            Enumeration enum = bookVector.elements();
            
            SearchDialog aBook = null;
            String name = null;
            String author = null;
            
            String publish = null;
            String minprice = null;
            String maxprice = null;
            String minnum = null;
            String maxnum = null; // clear out the list first

        }
        
    /**
     *  Create a row w/ the name, email and company.  Format this row such that
     *  the items are equally spaced.
     */
    protected String createRow(String name, String author, String publish,String minprice,String maxprice,String minnum,String maxnum)
    {
    StringBuffer row = new StringBuffer();
    String temp = null;

    temp = padString(name);
    row.append(temp + "     "); temp = padString(author);
    row.append(temp + "     "); temp = padString(publish);
    row.append(temp + "     ");

    temp = padString(minprice);
    row.append(temp + "     ");

    temp = padString(maxprice);
    row.append(temp + "     ");

    temp = padString(minnum);
    row.append(temp + "     ");

    temp = padString(maxnum);
    row.append(temp + "     "); return row.toString();
    } /**
     *  Pads a string w/ extra spaces if it is shorter than the COLUMN_WIDTH
     */
    他说回复内容太长,让我分开,后面还有一部分applet内容,但可能关系不大了!!!!!!!!!!!!!!
      

  5.   

    这是紧跟上面的applet内容!太麻烦各位高手了!!!!!!!!!!11
    protected String padString(String text)
    {
    StringBuffer result = null;

    if (text.length() < COLUMN_WIDTH)
    {
    int count = COLUMN_WIDTH - text.length();
    result = new StringBuffer(text);

    for (int i=0; i < count; i++)
    {
    result.append(" ");
    }
    }
    else
    {
    result = new StringBuffer(text.substring(0, COLUMN_WIDTH));
    }

    return result.toString();
    }

        /**
         *  Register a new book.
         *
         *  This is accomplished by showing a registration dialog box.  The user
         *  enters name, e-mail, company, etc.  This information is 
         */
    protected void registerbook()
    {
        PrintWriter outTest = null;
        BufferedReader inTest = null;
        Book theBook = null;
        
        // show the dialog for registering books
        SearchDialog searchDialog = new SearchDialog(new Frame(), true);
        searchDialog.setVisible(true);
        
        // find out if user selected the register or cancel button
        if (searchDialog.isRegisterButtonPressed())
        {
            theBook = searchDialog.getBook();
                log("Register button: " + searchDialog.isRegisterButtonPressed());
        }
        else
        {
            // the cancel button was pressed, so do nothing and return
                log("Register button: " + searchDialog.isRegisterButtonPressed());
            return;
        }
        
            try
            {
                // connect to the servlet
            log("Connecting to servlet...");
                URL bookDBservlet = new URL( webServerStr );
                URLConnection servletConnection = bookDBservlet.openConnection();  
            log("Connected");            // inform the connection that we will send output and accept input
                servletConnection.setDoInput(true);          
            servletConnection.setDoOutput(true);
            
                // Don't used a cached version of URL connection.
                servletConnection.setUseCaches (false);            // Specify the content type that we will send binary data
                servletConnection.setRequestProperty
                    ("Content-Type", "application/octet-stream");
                                             
            // send the book object to the servlet using serialization
            sendbookToServlet(servletConnection, theBook);
                     
            // now, let's read the response from the servlet.
            // this is simply a confirmation string
                readServletResponse(servletConnection);         
                
                // now let's refresh the data list
                log("Refreshing the list");
                Vector bookVector = getBookList();
                displayBooks(bookVector);
                
        }
        catch (Exception e)
        {
            log(e.toString());    
        }
        
    } /**
     *  Sends a book object to a servlet.  The book object is serialized over the URL connection
     */
        protected void sendbookToServlet(URLConnection servletConnection, Book thebook)
        {
            ObjectOutputStream outputToServlet = null;
            
            try
            {
            // send the book object to the servlet using serialization
            log("Sending the book to the servlet...");
            outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
            
            // serialize the object
            outputToServlet.writeObject(thebook);
            
            outputToServlet.flush();         
            outputToServlet.close();
            log("Complete.");
            }
            catch (IOException e)
            {
              log(e.toString());    
            }
        }
        
    /**
     *  Reads a response from the servlet.
     */
        protected void readServletResponse(URLConnection servletConnection)
        {
            BufferedReader inFromServlet = null;
            
            try
            {
            // now, let's read the response from the servlet.
            // this is simply a confirmation string
            inFromServlet = new BufferedReader(new InputStreamReader(servletConnection.getInputStream()));
            
                String str;
                while (null != ((str = inFromServlet.readLine())))
                {
                    log("Reading servlet response: " + str);
                }
                
                inFromServlet.close();
            }
            catch (IOException e)
            {
              log(e.toString());    
            }
        }
        
    /**
     *  Simple logging method for status message in the text area.
     */
        protected void log(String msg)
    {
        statusTextArea.append(msg + "\n");    
    }   
    /////////////////////////////////////////////////////////
    //
    //  INNER CLASSES for EVENT HANDLING
    //

    /**
     *  When the display button is pressed, we simply get the
     *  book list and display the books in the GUI.
     */
    class DisplayButtonActionListener implements ActionListener
    {
    public void actionPerformed(ActionEvent event)
    {
    try
    {
    // Get a list of the books
    Vector bookVector = getBookList(); // Display the list of books
    displayBooks(bookVector);
    }
    catch (Exception e)
    {
    System.out.println("Error: " + e);
    }
    }
    } /** 
     *  When the "Register" button is pressed then we register
     *  the book in the database.
     */
    class RegisterButtonActionListener implements ActionListener
    {
    public void actionPerformed(ActionEvent event)
    {
    registerbook();
    }
    }}
      

  6.   

    你的applet有包
    应该这样
    <APPLET CODE="book.search_book.class" WIDTH=515 HEIGHT=417></APPLET>网页在book的上一层目录试试
      

  7.   

    也不行呀,出现java.lang.ClassNotFoundException: book.search_book.class
    的错误信息!!!!