这样的用法是不符合Struts模式的,真正的Struts模式,数据是在action中取得的,同时在action中对actionform的属性赋值,这样从action跳转到jsp页面后表单中的值就会显示了,
你的方法是在jsp页面中调用ResultSet对象取数据库中的数据,这和原来的jsp开发没有什么两样,只是形式上用了Struts标签,实际上根本就不是什么mvc模式,真正的mvc模式jsp页面上只用于显示数据结果.你应该先调用一个action,在action中调用DAO(数据访问)对象,读取数据库中的数据,给要跳转的jsp中的表单actionform中的各项属性赋值,然后再跳转到jsp页面,这才是真正的mvc模式,你用到的value属性是没有用的,只用property属性就可以动态赋值了.
你的方法是在jsp页面中调用ResultSet对象取数据库中的数据,这和原来的jsp开发没有什么两样,只是形式上用了Struts标签,实际上根本就不是什么mvc模式,真正的mvc模式jsp页面上只用于显示数据结果.你应该先调用一个action,在action中调用DAO(数据访问)对象,读取数据库中的数据,给要跳转的jsp中的表单actionform中的各项属性赋值,然后再跳转到jsp页面,这才是真正的mvc模式,你用到的value属性是没有用的,只用property属性就可以动态赋值了.
解决方案 »
- MINA框架中的sessionClosed
- struts里的javabean取值问题
- junit测试 泛型 javaEE bug
- ★★★★★EJB如何使用log4j?
- 将Log4J封装成一个class,但是使用该封装class,不能正常显示出调用该class的类名和方法名。
- 有关classpath的问题(在先等待,解决马上给分)
- 在家帮我看看这段代码哪错了?
- SAX解析"GBK"字符集问题
- java高手请进:同一个与底层硬件打交道的daemon程序,用java写出来的一定比用C写出来的耗费很多资源吗?
- 帮我看看(struts1.1)-datasource
- 问一个超级难题,保证谁都不会!
- 如何在J2EE服务器启动时加载一个Timer类,让它随着服务器一起启动,而不需要第一次运行它时要手动?
BeanUtils.setProperty(actionForm, property, 值(String));
BeanUtils.setArrayProperty(actionForm, property, 值(String[]));
送上sample一份
<%
String[] multiboxValues = (String[])request.getAttribute("multiboxValues");
for (int i = 0; i < multiboxValues.length; i++) {
%>
<html:multibox property="multiboxData">
<%= multiboxValues[i] %>
</html:multibox><%= multiboxValues[i] %><br>
<%
}
%>
下面大家自己去分析一下html:checkbox和html:multibox标签的源代码,相信可解决上述问题.
package org.apache.struts.taglib.html;
import javax.servlet.jsp.JspException;
import org.apache.struts.util.MessageResources;
import org.apache.struts.util.RequestUtils;
import org.apache.struts.util.ResponseUtils;
/**
* Tag for input fields of type "checkbox".
*
* @author Craig R. McClanahan
* @version $Revision: 1.17 $ $Date: 2002/11/16 06:05:21 $
*/public class CheckboxTag extends BaseHandlerTag {
// ----------------------------------------------------- Instance Variables
/**
* The message resources for this package.
*/
protected static MessageResources messages =
MessageResources.getMessageResources(Constants.Package + ".LocalStrings");
/**
* The name of the bean containing our underlying property.
*/
protected String name = Constants.BEAN_KEY; public String getName() {
return (this.name);
} public void setName(String name) {
this.name = name;
}
/**
* The property name for this field.
*/
protected String property = null;
/**
* The body content of this tag (if any).
*/
protected String text = null;
/**
* The server value for this option.
*/
protected String value = null;
// ------------------------------------------------------------- Properties
/**
* Return the property name.
*/
public String getProperty() { return (this.property); }
/**
* Set the property name.
*
* @param property The new property name
*/
public void setProperty(String property) { this.property = property; }
/**
* Return the server value.
*/
public String getValue() { return (this.value); }
/**
* Set the server value.
*
* @param value The new server value
*/
public void setValue(String value) { this.value = value; }
// --------------------------------------------------------- Public Methods
/**
* Generate the required input tag.
* <p>
* Support for indexed property since Struts 1.1
*
* @exception JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException { // Create an appropriate "input" element based on our parameters
StringBuffer results = new StringBuffer("<input type=\"checkbox\"");
results.append(" name=\"");
// * @since Struts 1.1
if( indexed )
prepareIndex( results, name );
results.append(this.property);
results.append("\"");
if (accesskey != null) {
results.append(" accesskey=\"");
results.append(accesskey);
results.append("\"");
}
if (tabindex != null) {
results.append(" tabindex=\"");
results.append(tabindex);
results.append("\"");
}
results.append(" value=\"");
if (value == null)
results.append("on");
else
results.append(value);
results.append("\"");
Object result = RequestUtils.lookup(pageContext, name,
property, null);
if (result == null)
result = "";
if (!(result instanceof String))
result = result.toString();
String checked = (String) result;
if (checked.equalsIgnoreCase(value)
|| checked.equalsIgnoreCase("true")
|| checked.equalsIgnoreCase("yes")
|| checked.equalsIgnoreCase("on"))
results.append(" checked=\"checked\"");
results.append(prepareEventHandlers());
results.append(prepareStyles());
results.append(getElementClose()); // Print this field to our output writer
ResponseUtils.write(pageContext, results.toString()); // Continue processing this page
this.text = null;
return (EVAL_BODY_TAG); } /**
* Save the associated label from the body content.
*
* @exception JspException if a JSP exception has occurred
*/
public int doAfterBody() throws JspException { if (bodyContent != null) {
String value = bodyContent.getString().trim();
if (value.length() > 0)
text = value;
}
return (SKIP_BODY); }
/**
* Process the remainder of this page normally.
*
* @exception JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException { // Render any description for this checkbox
if (text != null)
ResponseUtils.write(pageContext, text); // Evaluate the remainder of this page
return (EVAL_PAGE); }
/**
* Release any acquired resources.
*/
public void release() { super.release();
name = Constants.BEAN_KEY;
property = null;
text = null;
value = null; }
}
<html:multibox property="stringMultibox" value="1" />
如果把这句写在JSP中,那么当JSP第一次被编译时运行时,form bean里的stringMultibox将和1进行比较,如果等于1,这个框就是选中的,当提交时就提交1,当然,你也可以改变他
记得在第一次运行JSP时,这个VALUE不是赋值,而是比较!!!
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>这些东西 嘿嘿