JSP - Netbeans 无法使用会话 bean
已解决:如果您像我一样遇到麻烦,请仔细检查您的构造函数定义! 由于某种与忍者相关的原因,我的账户是私有的。
大家好,
我是 NetBeans-JSP 编程新手(我对 PHP 很有信心) 您好,“doLogin.jsp”中有此指令:
...
<jsp:useBean scope="request" id="user" class="minibay.user.LoginBean" />
<jsp:useBean scope="session" id="userSession" class="minibay.user.UserSessBean" />
...
当我运行应用程序并转到该页面时,我收到此错误:
org.apache.jasper.JasperException: /doLogin.jsp(12,0) The value for the useBean class attribute minibay.user.UserSessBean is invalid.
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)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
实际上,该类位于“MiniBay/java/minibay/user”下(其中 MiniBay 是项目根目录)
我在其他文章中读到我的类应该位于“WEB-INF”文件夹下。 事实上,我曾尝试移动它们,但没有成功。
此外,“user”bean 运行良好,如果我删除上面代码的第二行,就没有问题。
知道如何让它发挥作用吗?
thnks
编辑:这是 UserSessBean 类定义:
package minibay.user;
import java.io.Serializable;
/**
*
* @author Alessandro Artoni <[email protected]>
*/
public class UserSessBean implements Serializable{
private boolean loggedIn;
private User user;
private UserSessBean(){
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public boolean isLoggedIn() {
return loggedIn;
}
public void setLoggedIn(boolean loggedIn) {
this.loggedIn = loggedIn;
}
}
Solved: if you run in trouble like me doublecheck your constructor definition!
mine was for some ninja-releated reason private.
Hi everyone,
i'm new to NetBeans-JSP programming (i'm quite confident with PHP)
hi have this instruction in "doLogin.jsp":
...
<jsp:useBean scope="request" id="user" class="minibay.user.LoginBean" />
<jsp:useBean scope="session" id="userSession" class="minibay.user.UserSessBean" />
...
when I run the application and go to the page I recive this error:
org.apache.jasper.JasperException: /doLogin.jsp(12,0) The value for the useBean class attribute minibay.user.UserSessBean is invalid.
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)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
Actually, the class is located under "MiniBay/java/minibay/user" (where MiniBay is the project root)
I've read in other post that my classes should be located under the "WEB-INF" folder.
Actually, ii've tried to move them with no succes.
Furthermore, the "user" bean works well, if I remove the second line of the code above I have no problem.
Any Idea of how to make it work out?
thnks
Edit: this is the UserSessBean class definition:
package minibay.user;
import java.io.Serializable;
/**
*
* @author Alessandro Artoni <[email protected]>
*/
public class UserSessBean implements Serializable{
private boolean loggedIn;
private User user;
private UserSessBean(){
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public boolean isLoggedIn() {
return loggedIn;
}
public void setLoggedIn(boolean loggedIn) {
this.loggedIn = loggedIn;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可以归结为以下内容惨败:
它是否有一个(隐式)公共无参数构造函数?它应该在那里让施工正常进行。还要注意任何(静态)初始化块运行时不会抛出运行时异常/错误。然而,您应该已经在服务器日志中看到了这一点作为根本原因。
另请参阅:
This boils down that the following has failed miserably:
Does it have an (implicit) public no-arg constructor? It should be there to get construction to work. Also take care that any of (static) initialization blocks runs without throwing runtimeexceptions/errors. You should however have seen that back in the server logs as root cause.
See also: