struts中的html:checkbox 怎么用

type Exception report

message

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

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /login.jsp at line 13

10:
11: dygf
12:
13: checkbox1
14: checkbox2
15:
16: html:reset/html:reset

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean checkbox in any scope
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.login_jsp._jspService(login_jsp.java:94)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

javax.servlet.jsp.JspException: Cannot find bean checkbox in any scope
org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:938)
org.apache.struts.taglib.html.CheckboxTag.doStartTag(CheckboxTag.java:207)
org.apache.jsp.login_jsp._jspx_meth_html_005fcheckbox_005f0(login_jsp.java:243)
org.apache.jsp.login_jsp._jspx_meth_html_005fform_005f0(login_jsp.java:158)
org.apache.jsp.login_jsp._jspx_meth_html_005fhtml_005f0(login_jsp.java:119)
org.apache.jsp.login_jsp._jspService(login_jsp.java:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
另外html:checkbox的name属性有什么用

9个回答

那拿它的例子跑一跑看,自己再看它代码,懂了之后,再自己手写代码,可以以这种学习方式来快速完成

javax.servlet.jsp.JspException: Cannot find bean checkbox in any scope

找不到名字为“checkbox ”的bean

其实使用很简单的,你查一下代码看有没什么问题

在formbean的属性最好是用String[]

FormBean:
public class LoginForm extends ActionForm {
private String password;
private String username;
private String[] hobby;
接着一些Getters & Setters

Action:
public ActionForward execute(...) {
LoginForm loginForm = (LoginForm) form;
for(int i = 0; i < loginForm.getHobby().length; i++) {
System.out.println(loginForm.getHobby()[i]);
}
}

JSP:

Username :

password :

Hobby:

Java/html:checkbox
VC/html:checkbox
VB/html:checkbox

html:submit/html:cancel/
/html:form

那当然就不行了
这个formbean是要符合javabean的规范,

必须要用get,set方法,struts框架才能反射调用把值设置进去

比如属性为checkbox
那相应的get,set方法就是

public String[] getCheckbox(){return this.checkbox ;}
public void setCheckbox( String[] checkbox){ this.checkbox = checkbox ;}

get,set方法是可以通过eclipse自动生成的

多学会使用开发工具,它本身提供一定的代码生成和重构
[img]http://dl.iteye.com/upload/attachment/217920/582e45b6-c4ee-3d65-8b69-837c7f766fa5.jpg[/img]

自动生成getters,setters方法是右击当前类,就会出现我发的图片的菜单

html:checkbox 的属性是要数组类型的,不是boolean

我建议你从网上先找一个例子来入手,可能环境还是代码某个地方搞出问题导致一直这样

你说看的教材,真怕教材把你给误导了,搞得好的资料,至少例子要能跑得起来的,不然让人能学到什么东西

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐