在 jsp 中提交 form 表单到action ; 无刷新上传; 注意和servlet 上传区别;

来源:互联网 发布:nagios 监控windows 编辑:程序博客网 时间:2024/05/16 15:38
 action 中; 返回值是null;------------------
     public String addEmployee() {

        Employee e = new Employee();
        e.setAge(age);
        e.setBirthday(birthday);
        e.setEmail(email);
        e.setEmployeeNumber(employeeNumber);
        e.setName(name);

        if (orgid != null) {
            Organise org;
            try {
                org = (Organise) this.organiseService.findById(orgid);
                e.setOrganise(org);
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

        }
        e.setPassword(password);
        e.setRole(role);
        e.setSex(sex);
        e.setTelphone(telphone);
      
            this.employeeService.save(e);
    
                ServletActionContext.getResponse().getWriter().print("<script>window.parent.uploadSuccess('success');</script>");
                //getWriter().write("<script>window.parent.afterSumbmit(' not ok')</script>");
     
            ServletActionContext.getResponse().getWriter().print("<script>window.parent.uploadSuccess('not ok');</script>");
 

        return null; / / 返回值是null;
    }


//---------------------------------------------------jsp 页面



<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'test.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    
    -->
    
    <script type="text/javascript">
    
     function testsub(){
        document.getElementById('myform').submit();
        }
        


         function uploadSuccess(msg){

             alert(msg);


        }
         </script>

  </head>
 
 
  <body>
   <iframe style="display: none" name="hiddenifr"></iframe>        // ifram e 可以再form 里面或者外面都可以;;似乎没什么影响;
       <form action="addEmployeeAction.action" method='post'
                                        target='hiddenifr' id="myform">
                                
                                        
                                        <input name='employeeNumber' value='employeeNum'>
                                        
                                        <input type ='button' onclick="testsub()">
    </form>
  </body>
</html>




原创粉丝点击