• ActionForm_空字段问题


    <li>空字段测试</li><br>
       <form action="blankfield.do" method="post">
        姓名:<input type="text" name="username"><br>
        <input type="submit" value="提交">
       </form>

    建立一个BlankFieldActionForm接收空字段

    package com.bjsxt.struts;

    import org.apache.struts.action.ActionForm;

    /**
     * 测试空字段
     * @author Administrator
     *
     */
    public class BlankFieldActionForm extends ActionForm {

     private String username;
     
     private String password;

     public String getUsername() {
      return username;
     }

     public void setUsername(String username) {
      this.username = username;
     }

     public String getPassword() {
      return password;
     }

     public void setPassword(String password) {
      this.password = password;
     }
    }

    建立Action:

    package com.bjsxt.struts;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;

    /**
     * 测试空字段
     * @author Administrator
     *
     */
    public class BlankFieldTestAction extends Action {

     @Override
     public ActionForward execute(ActionMapping mapping, ActionForm form,
       HttpServletRequest request, HttpServletResponse response)
       throws Exception {
      return mapping.findForward("success");
     }

    }

    配置:

    <action path="/blankfield"
        type="com.bjsxt.struts.BlankFieldTestAction"
        name="blankFieldForm"
        scope="request"  
      >
       <forward name="success" path="/blankfield_success.jsp"/>
      </action>

    jsp测试页面:

    <body>
     <%
      BlankFieldActionForm form = (BlankFieldActionForm)request.getAttribute("blankFieldForm");
      %>
     <li>jsp脚本</li><br>
     姓名:<%=form.getUsername() %><br>
     密码:<%=form.getPassword() %><br>
     <p>
     <li>el表达式</li><br>
     姓名:${blankFieldForm.username }<br>
     密码:${blankFieldForm.password }<br>
    </body>

    在空字段中jsp脚本得到的是null空对象,而el表达式得到的是一个空字符串。

  • 相关阅读:
    yii框架中的各种小问题
    yii框架无限极分类的做法
    yii框架中的下拉菜单和单选框
    yii框架定时任务的操作
    yii框架里DetailView视图和GridView的区别
    git的使用(1)
    mysql 连接问题
    PHP字符串函数
    phpdocmentor 生成php 开发文档(转载)
    使用Nginx的X-Accel-Redirect实现大文件下载
  • 原文地址:https://www.cnblogs.com/jinzhengquan/p/1953909.html
Copyright © 2020-2023  润新知