You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Pham, Tim" <tp...@vignette.com> on 2000/08/22 01:19:20 UTC

is it a bug?

I just got this strange error an example in "Web Development with JSP" book.
The JSP file is:
---------------------------------------
<%@ page import="java.io.*" %>

<%!
public String runCmd(String cmd) {
  try {
	Runtime rt = Runtime.getRuntime();
	Process p = rt.exec( cmd );

	InputStreamReader in = new InputStreamReader(p.getInputStream());
	BufferedReader reader = new BufferedReader(in);

	StringBuffer buff = new StringBuffer();
	String line, newline = "\n";
	while ((line = reader.readLine()) != null) {
		buff.append(line + newline);
	}
	reader.close();
	p.getInputStream().close();
	p.getOutputStream().close();
	p.getErrorStream().close();
	p.waitFor();
	return buff.toString();
      }
      catch (Exception e) {
	e.printStackTrace();
	return (e.getMessage());
      }
  }
}
%>

Executing <%= request.getParameter("command") %><br>
<hr>
<%= runCmd(request.getParameter("command")) %>
<hr>
<form action="<%= HttpUtils.getRequestURL(request) %>" method="post">
<input type="text" name="command">
<input type="submit" name="Enter command to run">
</form>
----------------------------------------------

There is nothing special about it. But I always got Error 500 with the
following
message:

"org.apache.jasper.JasperException: Unable to compile class for
JSPE:\apache\tomcat\work\localhost_8080\_0002fcommand_0002ejspcommand_jsp_0.
java:48: Class or interface declaration expected.
    static {
    ^
E:\apache\tomcat\work\localhost_8080\_0002fcommand_0002ejspcommand_jsp_0.jav
a:16: class _0002fcommand_0002ejspcommand_jsp_0 must be declared abstract.
It does not define void _jspService(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse) from class
org.apache.jasper.runtime.HttpJspBase.
public class _0002fcommand_0002ejspcommand_jsp_0 extends HttpJspBase {
             ^
2 errors

        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:247)
..."

----------------------------------------------
I look at temporary java file created from this jsp, and strange enough they
have that line
"static {
}"

It does have the function "void _jspService(..)" defined.
Here is the file (clipped):

.....
import java.io.*;

public class _0002fcommand_0002ejspcommand_jsp_0 extends HttpJspBase {

    // begin [file="E:\\command.jsp";from=(2,3);to=(29,0)]
        
        public String runCmd(String cmd) {
          try {
        	Runtime rt = Runtime.getRuntime();
        	Process p = rt.exec( cmd );      
		...
        }
    // end

    static {
    }
    public _0002fcommand_0002ejspcommand_jsp_0( ) {
    }

    private static boolean _jspx_inited = false;

    public final void _jspx_init() throws JasperException {
    }

    public void _jspService(HttpServletRequest request, HttpServletResponse
response)
        throws IOException, ServletException {
	...
   }
}
---------------------------------------

So, why is it generated with that empty "static {}" line, and why does it
complain about
_jspService() function?

BTW, I tested the JSP function in another java class, and everything's
working fine.
Thanks for your help,

----------------- Tim Pham -------------------
QA Engineer  -  Vignette Corporation
----------------------------------------------

Re: is it a bug?

Posted by "Kurt B. Pruenner" <le...@gmx.at>.
"Pham, Tim" wrote:
> I just got this strange error an example in "Web Development with JSP" book.
> The JSP file is:
> ---------------------------------------
> <%@ page import="java.io.*" %>
> 
> <%!
> public String runCmd(String cmd) {
>   try {
<snip>
>       }
>       catch (Exception e) {
<snip>
>       }
>   }
> }
  ^
Methinks you've got one closing curly brace too many in there, thus closing a
block that was started by the code Jasper encloses your code with - this
always leads to funny error messages somewhere else in the code. Try removing
it, and see what happens...

Wait, did I say "code" a bit too often here? ;)

> %>

-- 
Kurt Pruenner - Haendelstrasse 17 - 4020 Linz - Austria
http://www.mp3.com/Leak - http://www.ssw.uni-linz.ac.at

np: Spooky - Fingerbobs (Found Sound)