By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,584 Members | 1,750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,584 IT Pros & Developers. It's quick & easy.

JSP error & Java class for rs232

P: n/a
Dan
I wnat to see in browser an status from an device connected on rs232
port

The java class for read from serial port is:

//Serial.java
import java.io.*;
import java.util.*;
import java.lang.*;
import javax.comm.*;
public class Serial implements SerialPortEventListener
{

SerialPort port;
CommPortIdentifier ID;
InputStream in;
OutputStream out;
String text1="ok";

public void alarm(){

try
{
ID = CommPortIdentifier.getPortIdentifier("COM1");
port = (SerialPort)ID.open("alarm",1000);
in = port.getInputStream();
out = port.getOutputStream();
port.notifyOnDataAvailable(true);
port.setSerialPortParams (19200, port.DATABITS_8, port.STOPBITS_1,
port.PARITY_NONE);
port.setFlowControlMode(port.FLOWCONTROL_NONE);
}
catch (Exception e) {}

}

public void serialEvent(SerialPortEvent e)
{
int data = 0;
String text1;

switch(e.getEventType())
{
case SerialPortEvent.DATA_AVAILABLE:
try
{
while (in.available() > 0)
{
data=in.read();
if ('S' == (char)data)
{
data=in.read();
update_status(data);
}
}
}
catch (IOException ev) {}
break;
}
}

public String update_status (int s)
{
int temp = s;
int val = temp & 0x01;

if (val==0x01)
text1 = "ok";
else
text1 = "not ok";

return text1;
}

}//end class

Tha jsp page is :
//RS232.jsp

<%@ page import="Serial" %>
<HTML>
<HEAD>
<TITLE>Using a JavaBean</TITLE>
</HEAD>

<BODY>
<% Serial rs232 = new Serial(); %>

The status is: <%= rs232.update_status() %>

</BODY>
</HTML>

I started Apache Tomcat 5.0 server (run on Winxp); I put RS232.jsp in
"webapps/Root" and Serial.class in "webapps/Root/WEB-INF/classes

On executing "http://localhost/RS232.jsp" I have an error :

//....................
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: -1 in the jsp file: null

Generated servlet error:
[javac] Compiling 1 source file

C:\Tomcat5\work\Catalina\localhost\_\org\apache\js p\RS232_jsp.java:6:
'.' expected
import Serial;
^
1 error
//...........................

What can be wrong????
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: 4
hello, i'm hani. i'm learning to use servlet in read serial port. i'll try to run your program. the error is it can't read update_status(). only. have you figure what's wrong with the code. just want to know. thank you
Mar 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.