action是逻辑处理bean,actionform是数据bean
解决方案 »
- 小女子 请问这个多线程下载 网上资源 咋重复下载相同的资源
- java 怎么把Excel文件里的图片读取到某个指定的文件夹?
- powerdesigner怎么生成尸体类
- Google 搜索周边
- 超多JAVA,DotNet视频共享 [希望能置顶让更多朋友下载到]
- 请问大家在项目中什么时候用ANT?
- structs中的一个关于页面显示的问题?
- hibernate 代码自动生成
- smartupload奇怪的乱码问题---在线等!!
- hibernate 连接mysql问题
- 小问题--轻松拿高分--EJB可以直接调用MSSQL Server的存储过程吗?
- java初学 发现线程难理解阿 实际开发中线程用的多吗???
帮我看看代码,谢谢
总是转向welcome.jsp,看不到actionform的效果在哪
3.5.1 Using the Struts ActionForm
Struts ActionForm objects are used in the framework to pass client input data back and forth between the user and the business layer. The framework automatically collects the input from the request and passes this data to an Action using a form bean, which then can be passed along to the business layer. To keep the presentation layer decoupled from the business layer, you should not pass the ActionForm itself to the business layer; rather, create the appropriate DTO using the data from the ActionForm. The following steps illustrate how the framework processes an ActionForm for every request: 1. Check the mapping for the action and see if an ActionForm has been configured. 2. If an ActionForm is configured for the action, use the name attribute from the action element to look up the form bean configuration information. 3. Check to see if an instance of the ActionForm already has been created. 4. If an ActionForm instance is present in the appropriate scope and it's the same type as needed for the new request, reuse it. 5. Otherwise, create a new instance of the required ActionForm and store it in the appropriate scope (set by the scope attribute for the action element). 6. Call the reset( ) method on the ActionForm instance. 7. Iterate through the request parameters, and populate every parameter name that has a corresponding setter method in the ActionForm with the value for that request parameter. 8. Finally, if the validate attribute is set to "true", invoke the validate( ) method on the ActionForm instance and return any errors. For every HTML page where form data is posted, you should use an ActionForm. The same ActionForm can be used for multiple pages if necessary, as long as the HTML fields and ActionForm properties match up. Example 3-5 shows the com.oreilly.struts.banking.form.LoginForm that is used with the banking application.
不会我看漏了一点
public class LoginAction extends Action {
public ActionForward execute( ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response )
throws Exception {
........................中form就是相对应的actionform,要强制转化后才能使用public class LoginForm extends ActionForm {
// The user's private ID number
private String pinNumber;
// The user's access number
private String accessNumber;
public LoginForm( ) {
super( );
resetFields( );
}
/**
* Called by the framework to validate the user has entered values in the
* accessNumber and pinNumber fields.
*/
public ActionErrors validate(ActionMapping mapping, HttpServletRequest req ){
ActionErrors errors = new ActionErrors( );
.........................不过我还是不清楚:ActionErrors返回给谁呢?如果返回的不是null值,又应当有什么反应呢?请赐教。谢谢
if ((errors == null) || errors.isEmpty()) {
if (log.isTraceEnabled()) {
log.trace(" No errors detected, accepting input");
}
return (true);
} // Special handling for multipart request
if (form.getMultipartRequestHandler() != null) {
if (log.isTraceEnabled()) {
log.trace(" Rolling back multipart request");
}
form.getMultipartRequestHandler().rollback();
} // Has an input form been specified for this mapping?
String input = mapping.getInput();
if (input == null) {
if (log.isTraceEnabled()) {
log.trace(" Validation failed but no input form available");
}
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
getInternal().getMessage("noInput",
mapping.getPath()));
return (false);
} // Save our error messages and return to the input form if possible
if (log.isDebugEnabled()) {
log.debug(" Validation failed, returning to '" + input + "'");
}
request.setAttribute(Globals.ERROR_KEY, errors); if (moduleConfig.getControllerConfig().getInputForward()) {
ForwardConfig forward = mapping.findForward(input);
processForwardConfig( request, response, forward);
} else {
internalModuleRelativeForward(input, request, response);
} return (false);
这是Struts中处理Form的一段代码,从上面可以看出validate返回如果不是null,则会放回到inputPage
中显式调用public class LoginForm extends ActionForm {.........
中的代码是吗?那么,配置文件中
<action-mappings>
<action path="/login"
type="com.self.struts.actions.LoginAction"
name="LoginForm"
input="/login.jsp"
validate="true" ///////////这又有什么用?
scope="request">
<forward name="Success" path="/welcome.jsp"/>
<forward name="Failure" path="/login_error.jsp"/>
</action>
我想,validate属性设为true后,是不是系统就会自动处理,比如:errors 不为空就返回到表单页,如果在代码中调用了validate那么,不管validate属性是不是true,都调用了validate
这样,这个validate属性不是没什么用吗?
在tomcat中,好象不管validate属性怎设都转向welcome.jsp
在resin中,好象不管validate属性怎设都不反应,(只要返回的errors不为空)
validate的属性后重启服务或重新编译一次actionform的那个类好象就有反应了。
比如,返回的error不为空时
validate设为true,提交表单它就不会跳到welcome.jsp去,而是留在表单页
反之,若validate设为false,就会跳到welcome.jspaction-mappings>
<action path="/login"
type="com.self.struts.actions.LoginAction"
name="LoginForm"
input="/login.jsp"
validate="true" ///////////这又有什么用?
scope="request">
<forward name="Success" path="/welcome.jsp"/>
<forward name="Failure" path="/login_error.jsp"/>
</action>
("com.self.struts.errors.InvalidLoginError");
errors.add (ActionErrors.GLOBAL_ERROR, newError);
return errors; //这个值返回给谁用的?好象没反应啊
}
erres 是个对象集,里面是errer。返回到,input的jsp
errors返回到input的jsp?
那么也没见到有什么反应啊?
我自己觉得它的作用有点象脚本,
<bean:message key="prompt.pageNote"/> : //显示资源文件prompt.pageNote
<html:textarea name="pageForm" property="pageNote"/>//用form里的validate="true“方法
html:errors property="pageNote"/></br>//显示资源文件里的error.pageNote的地方
你是说要在jsp脚本里使用
<bean:message
<html:errors
等标记?
能不能介绍下它的所有参数含义?
<html:errors
标记所在的地方就是显示错误的地方?
还有,在这里的出错信息是不是要在xml文件里定义?
Action 实际上就是Ctrl,用来控制你的事务逻辑的处理.