Struct 例子提供了很多标签的使用,我有个不明白

03-12-12 cute

在Struct例子中 是这样的写法:

<jsp:useBean id="testbean" scope="session" class="org.apache.struts.webapp.exercise.TestBean"/>


<html:select property="beanCollectionSelect" size="10" multiple="true">
<html:optionsCollection name="testbean" property="beanCollection"/>
</html:select>
<p>

而我用easy struct

我在ACTION 中这样保存FormBean:

LoginForm loginForm = (LoginForm) form;

request.setAttribute("aaa",loginForm);

必须让我加上:name="aaa"

请问为什么?

<html:select name="aaa" property="beanCollectionSelect" size="11" multiple="true">
<html:optionsCollection name="aaa" property="beanCollection"/>
</html:select>
<p>

cute
2003-12-12 11:10

如果我不加:

name="aaa"

<html:select  property="beanCollectionSelect" size="11" multiple="true">
<p>

就会出现下列问题: 帮忙解决??

javax.servlet.ServletException: Cannot find bean org.apache.struts.taglib.html.BEAN in any scope
	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
	org.apache.jsp.ok_jsp._jspService(ok_jsp.java:95)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
	org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
	org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
	org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
	cute.struts.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
<p>

不吃羊肉
2003-12-12 13:37

当你的<html:xxx>标签嵌于<html:form>标签的内部,是可以不填写name属性的,假设该<html:form>对应的form叫做SampleForm(定义在struts-config里),jsp页面运行的时候将从上下文中寻找名称为SampleForm的bean然后将其作为上下文执行<html:xxx>标签对应生成的代码。

否则,必须指定name属性,用来在servlet content,session,request或者page里寻找一个bean

cute
2003-12-15 10:29

我就是在XML中定义好了actionform,就是找不到呀。

你的意思我不太理解。。

再问一个:下面的代码有何区别:(nested 使用)

<bean:define id="test2_boolean" name="test2" property="nested.booleanProperty"/>

<bean:define id="test2_boolean" name="test2" property="booleanProperty"/>

cute
2003-12-16 09:42

为什么 错误一定要 保存在 :

ActionErrors.GLOBAL_ERROR

Action.ERROR_KEY

中呢 ??

  errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("globalError"));
  request.setAttribute(Action.ERROR_KEY, errors);


<p>