Newsgroup: it.comp.java
Titolo: jsp +classe

mettiamo che io ho una pag jsp che dichiara
<%@ page language="java" import="java.util.*,riccardo.*" %>
dove riccardo è il nome del  package che contiene una classe di nome
SimpleReadWrite1 che è la seguente (vi posto il codice):
package riccardo;
import java.io.InputStream;
   import java.io.OutputStream;
   import java.io.IOException;
import java.sql.*;
import java.util.Timer;
import java.util.TimerTask;
   import java.util.TooManyListenersException;
   import javax.comm.*;
/**
 * Simple program to read characters from the command-line, send
 * them to the specified serial port, and echo any characters
returned.
 * Modeled after the SimpleRead and SimpleWrite sample programs
included
 * with the Java Communications API distribution.
 */
    public class SimpleReadWrite1 implements Runnable,
SerialPortEventListener
	{
   String c;
      static String DEFAULT_PORT = "COM4";
      Connection con = null;
      InputStream  in;
      OutputStream out;
      private String message = "ATI6\r";
     boolean t = true;
      Thread readerThread;
      SerialPort serialPort;
	protected static Object srw;
      public void writeToCommPort(String message)  {
        this.message = message;
      }
    /**
     * Main method.
     */
     public static void main(String[] args) {
         String portname = DEFAULT_PORT;
         if (args.length > 1) {
            System.err.println("Usage: java SimpleReadWrite
[port_name]");
            System.exit(1);
         }
         else if (args.length == 1) {
            portname = args[0];
         }
         try {
            CommPortIdentifier portId =
CommPortIdentifier.getPortIdentifier(portname);
            if (portId.getPortType() ==
CommPortIdentifier.PORT_SERIAL) {
               SimpleReadWrite1 srw = new SimpleReadWrite1(portId);
            }
            else {
               System.err.println(portname + " is not a serial port");
               System.exit(1);
            }
         }
             catch (NoSuchPortException e) { //Port nicht vorhanden
               System.err.println("No such port: " + portname);
               System.exit(1);
            }
             catch (PortInUseException e) { //Port ist
gesperrt/inGebrauch
               System.err.println("Port in use: " + portname);
               System.exit(1);}
             }
    /**
     * Constructor.
     */
       public SimpleReadWrite1(CommPortIdentifier portId) throws
PortInUseException {
         try {
            SerialPort serialPort = (SerialPort)
portId.open("SimpleReadWrite",
                                                             2000);
//Port mit
            in  = serialPort.getInputStream();
            out = serialPort.getOutputStream();
           serialPort.addEventListener(this);
            serialPort.notifyOnDataAvailable(true);
            serialPort.setSerialPortParams(9600,
//Schnittstelleneinstellungen initialisieren
                                           SerialPort.DATABITS_8,
                                           SerialPort.STOPBITS_1,
                                           SerialPort.PARITY_NONE);
            Thread readerThread = new Thread(this);
            //readerThread.setDaemon(true);
            readerThread.start();
         } //Exception-Handling
             catch (IOException e) {
               System.err.println("Problem opening streams");
               System.exit(1);
            }
             catch (TooManyListenersException e) {
               System.err.println("Too Many Listeners");
               System.exit(1);
            }
             catch (UnsupportedCommOperationException e) {
               System.err.println("Problem setting port parameters");
               System.exit(1);
            }
      }
    /**
	 * @param b
	 */
	/**
     * This method loops forever, reading data from the
     * command line and writing it directly to the serial port.
     * No buffering is performed.
	 * @throws InterruptedException
     */
       public void run() {
         try {
            while(true){
			synchronized(this){
               out.write(message.getBytes());
          wait();
            } }
         }
             catch (IOException e) {
            // Terminate thread
            } catch (InterruptedException e) {
				// TODO Blocco catch generato automaticamente
				e.printStackTrace();
			}/*byte[] readBuffer = new byte[1];
            try {
                while (in.available() > 0) {
                   int numBytes = in.read(readBuffer);
                }
               System.out.print(new String(readBuffer));
            //   readerThread.interrupt();
       //  readerThread=null;
             }
                 catch (IOException e) {
                  // Terminate handling this event on read error
                }*/}
      /* public boolean stopThread() throws IOException{out.close();
       in.close();return t=false;}*/
    /**
     * Process serial port events.  This method is required
     * when implementing SerialPortEventListener
     *
     * @param event SerialPortEvent object to process
     */
     public void serialEvent(SerialPortEvent event) {
       	String a;
         switch (event.getEventType()) {
            case SerialPortEvent.BI:
            case SerialPortEvent.OE:
            case SerialPortEvent.FE:
            case SerialPortEvent.PE:
            case SerialPortEvent.CD:
            case SerialPortEvent.CTS:
            case SerialPortEvent.DSR:
            case SerialPortEvent.RI:
            case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
               break;
            case SerialPortEvent.DATA_AVAILABLE:
                // If there is data available on serial port,
                // read it in in chunks <=20 bytes
                //
               byte[] readBuffer = new byte[1];
               try {
                  while (in.available() > 0) {
                     int numBytes = in.read(readBuffer);
                  }
      String   c=toString(new String(readBuffer));
              //System.out.print(new String(readBuffer));
                 new Timer(true).schedule(new TimerTask() {
                    public void run() {
                     //System.out.println("Preparing to interrupt");
                    try{  readerThread.interrupt();
                      readerThread = null;}
                    catch(NullPointerException npe){System.exit(0);}//
to release it
                    }
                  }, 2000); // run() after 2000 milliseconds
               }
                   catch (IOException e) {
                    // Terminate handling this event on read error
                  }
               break;
            default:
               System.out.print("Unknown SerialPortEvent type = " +
                                 event.getEventType());
               break;
         }
      }
	/**
	 *
	 */
	/**
	 * @param string
	 */
	public String toString(String string) {System.out.print(string);
		return string;
		// TODO Stub di metodo generato automaticamente
	}
         }
   MI CHIEDO COSA DEBBO FARE PER FAR GIRARE LA MIA CLASSE COME SE LA
MANDASSI IN ESECUZIONE DALLA LINEA DI COMANDO QUALI ISTRUZIONI  DOVREI
SCRIVERE?,ANCHE PERCHE'SE SCRIVO la mia pag JSP in questo modo:
<%@ page language="java" import="java.util.*,riccardo.*,javax.comm.*"
%>
<%! String portname ="COM4";
%>
<%
String path = request.getContextPath();
String basePath =
request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP 'Prova.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>
  <body>
    <%   try {
            CommPortIdentifier portId =
CommPortIdentifier.getPortIdentifier(portname);
            if (portId.getPortType() ==
CommPortIdentifier.PORT_SERIAL) {
               SimpleReadWrite1 srw = new SimpleReadWrite1(portId);
            }
            else {
               System.err.println(portname + " is not a serial port");
               System.exit(1);
            }
         }
             catch (NoSuchPortException e) { //Port nicht vorhanden
               System.err.println("No such port: " + portname);
               System.exit(1);
            }
             catch (PortInUseException e) { //Port ist
gesperrt/inGebrauch
               System.err.println("Port in use: " + portname);
               System.exit(1);}
             }
       %>
  </body>
</html>
 E MODIFICO LA MIA CLASSE TOGLIENDO IL METODO MAIN POTREBBE ESSERE UNA
SOLUZIONE SECONDO VOI ? VI HO POSTATO IL CODICE così potete darmi
qualche dritta se potete o meglio se vi va di farlo grazie

questo è l'errore se lancio Prova.jsp(nome della jsp ) con tomcat:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented
it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
Generated servlet error:
C:\Jakarta\jakarta-tomcat-5.0.28\work\Catalina\localhost\finito\org\apache\jsp\Prova_jsp.java:35:
'try' without 'catch' or 'finally'
    try {
    ^
Generated servlet error:
C:\Jakarta\jakarta-tomcat-5.0.28\work\Catalina\localhost\finito\org\apache\jsp\Prova_jsp.java:104:
illegal start of type
    } catch (Throwable t) {
      ^
Generated servlet error:
C:\Jakarta\jakarta-tomcat-5.0.28\work\Catalina\localhost\finito\org\apache\jsp\Prova_jsp.java:114:
<identifier> expected
  }
  ^
Generated servlet error:
C:\Jakarta\jakarta-tomcat-5.0.28\work\Catalina\localhost\finito\org\apache\jsp\Prova_jsp.java:115:
'class' or 'interface' expected
}
^
Generated servlet error:
C:\Jakarta\jakarta-tomcat-5.0.28\work\Catalina\localhost\finito\org\apache\jsp\Prova_jsp.java:116:
'class' or 'interface' expected
^
5 errors
	org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
	org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
	org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

E' un errore di compilazione della classe, manca qualche parentesi graffa da
qualche parte.
-- 
---
Francesco Galli / Cinghiale Mannaro
Personal: 
http://cinghialemannaro.splinder.com
TMS project: 
http://tms.inera.it

grazie risolto una parentesi graffa di troppo alla fine