问题描述
我是用Myeclipse写程序的,我创建了一个webproject,命名位Jsp1,它自动生成了一个crs的文件夹和一个WebRoot的文件夹。然后我又新建了一个JSP(AdvancedTemplates),命名位jspbeanjsp,它被自动放到了WebRoot文件夹里。我创建了一个www.bag的包,被自动放到crs这个文件夹里,我在www.bag里新建了一个类JspBean1。jspbeanjsp.jsp代码<%@pagecontentType="text/html;charset=GB2312"%><html><head><title>MyJSP'jspbeanjsp.jsp'startingpage</title></head><h1>JavaBean动作</h1><jsp:useBeanid="JspBean1ID"scope="page"class="www.bag.JspBean1"/><h2>属性sampl的初始值:<jsp:getPropertyname="JspBean1ID"property="sampl"/></h2><jsp:setPropertyname="JspBean1ID"property="sampl"value="***新属性***"/><body><h2>属性sampl的新值:<jsp:getPropertyname="JspBean1ID"property="sampl"/></h2></body></html>
解决方案
解决方案二:
JspBean1.java代码publicclassJspBean1{privateStringsampl="Startvalue";publicStringgetSampl(){returnsampl;}publicvoidsetSampl(StringnewValue){if(newValue!=null){sampl=newValue;}}}
解决方案三:
返回的错误:typeExceptionreportmessagedescriptionTheserverencounteredaninternalerror()thatpreventeditfromfulfillingthisrequest.exceptionorg.apache.jasper.JasperException:/WebRoot/jspbeanjsp.jsp(7,0)ThevaluefortheuseBeanclassattributewww.bag.JspBean1isinvalid.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:148)org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1220)org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)org.apache.jasper.compiler.Node$Root.accept(Node.java:495)org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)org.apache.jasper.compiler.Generator.generate(Generator.java:3416)org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:231)org.apache.jasper.compiler.Compiler.compile(Compiler.java:347)org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)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:717)noteThefullstacktraceoftherootcauseisavailableintheApacheTomcat/6.0.26logs.