Passing class data directly with usebean

I have a class setting.java

and in this class I have read my data from a file and I want to use this data from jsp:useBean

in my page index.jsp

.

this class code below:

public class setting {

private  boolean setstatus=false;
private  String  title="Test";

public boolean changeheader(String text) {
    return true;
}

public boolean settitle(String  text) {
    return true;
}

public void getTitle() throws IOException{
    BufferedReader br ;
    try {
        br = new BufferedReader(new FileReader("C:\\Users\\Farshid\\workspace\\STPT\\WebContent\\file\\title.txt"));
        this.title = br.readLine();
        System.out.println("\nline: " + this.title + "\n");
        br.close();
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
        System.out.println("Error");
    }

}
}

      

And these are my index.jsp codes:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>

 </title>
</head>
<body>
 <jsp:useBean id="settitle" class="com.stpt.project.setting" scope="page">
 <jsp:getProperty property="title" name="settitle" />
 </jsp:useBean>
</body>
</html>

      

And these are my mistakes:

    type Exception report

    message Cannot find any information on property '*' in a bean of type 'com.stpt.project.setting'

   description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Cannot find any information on property '*' in a bean of type 'com.stpt.project.setting'
    org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:824)
    org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1081)
    org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1125)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2429)
    org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1380)
    org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1181)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
    org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2429)
    org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2435)
    org.apache.jasper.compiler.Node$Root.accept(Node.java:474)
    org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2377)
    org.apache.jasper.compiler.Generator.generate(Generator.java:3517)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:250)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

      

Finally my IDE is eclipse and my server is apache tomcat7.0.

+3


source to share


1 answer


You need the correct receiver for this class.

The required agreements are as follows:



  • The class must have a public default constructor (no arguments). This allows for easy instantiation through editing and activation.

  • Class properties must be accessed using get, set, (can be used for boolean properties instead of get) and other methods (called accessors and mutator methods) according to the standard naming convention. This makes it easy to automate checking and updating bean state within the framework, many of which include custom editors for different property types. Setters can have one or more arguments.

  • The class must be serializable. [This allows applications and frameworks to reliably save, save, and restore bean state in a VM- and platform-independent way.]

+1


source







All Articles