I have started to learn JSP and I tried to write my first JSP page and use <jsp:usebean/>
action tag.
The bean is an empty class that has no property and only one method print()
:
package foo;
import java.io.Serializable;
public class FirstBean implements Serializable {
public String print() {
return "hello, world";
}
}
I compiled the FirstBean.java file into foo directory which resides in the WEB-INF/classes directory. Then I have the FistBean.jsp file with the following content:
<html>
<head>
<jsp:usebean id="name" class="foo.firstBean"/>
</head>
<body>
<! String st=name.Print();%>
<p> the string stored in JSP is <%=st%></p>
</body>
</html>
In the above code I instantiate the firstBean instance via usebean
action. Then I call its print()
method which shoud return a String "Hello, world". But when I try to type localhost:8080/jsp/firstBean.jsp file Tomcat gives me the following error:
message /firstBean.jsp(3,7) Invalid standard action
description The server encountered an internal error that prevented it from fulfilling this request.
I get the following exception:
org.apache.jasper.JasperException: /firstBean.jsp(3,7) Invalid standard action org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40) org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407) org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88) org.apache.jasper.compiler.Parser.parseStandardAction(Parser.java:1131) org.apache.jasper.compiler.Parser.parseElements(Parser.java:1424) org.apache.jasper.compiler.Parser.parse(Parser.java:130) org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255) org.apache.jasper.compiler.ParserController.parse(ParserController.java:103) org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:185) org.apache.jasper.compiler.Compiler.compile(Compiler.java:354) org.apache.jasper.compiler.Compiler.compile(Compiler.java:334) org.apache.jasper.compiler.Compiler.compile(Compiler.java:321) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
It will be much appreciated if someone could help me with this issue.