Connecting an applet to a JSP.


    private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
      String last = lastField.getText(); // get data from screen
      String first = firstField.getText();
      String age = ageField.getText();
      String hair = (String)hairCombo.getSelectedItem();
     
      //
      // fix any spaces or special characters in the data
      //
      try{
        last = URLEncoder.encode(last, "UTF-8");
        first = URLEncoder.encode(first, "UTF-8");
        age = URLEncoder.encode(age, "UTF-8");
        hair = URLEncoder.encode(hair, "UTF-8");
      }
      catch(Exception ex)
      {
        JOptionPane.showMessageDialog(this,ex.toString());
        return;
      }
     
     
      try{
            // create a url with the data encoded on it
            URL link = new URL(getCodeBase()+"JspForm.jsp?"+
             "lastname="+last+ "&"+
             "firstname="+first+ "&"+
             "age="+age+"&"+
             "haircolor="+hair);
            getAppletContext().showDocument(link,"OutputWindow"); // Fire up the jsp and tell it where to send its output
       }

         catch(MalformedURLException ex) {
             JOptionPane.showMessageDialog(this, "Bad URL: JspForm.jsp");
     }
       
    }

JSP Reception of the parameters

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h3>Your Information :</h3>
        <%
          String last = request.getParameter("lastname");
          String first = request.getParameter("firstname");
          String age = request.getParameter("age");
          String haircolor = request.getParameter("haircolor");
       
        %>
        <b>Name : <%= first+" "+last %> </b><br/>
        <b>Age : <%= age %></b> <br/> 
        <b>Hair Color : <%= haircolor %> </b> <br/>
         
    </body>
</html>


Web page to contain both


<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Applet to JSP Connection Demo</h1>
    <Applet archive="AppletProject.jar" code="AppletForm.class" width="300" Height="260"></applet>
    <IFrame name="OutputWindow" width="300" height="300">
    </body>
</html>

Click here to download the NetBeans Project