WAP上传图片代码

来源:互联网 发布:ug四轴加工编程步骤 编辑:程序博客网 时间:2024/06/06 11:01

<?xml   version= "1.0 "   encoding= 'utf-8 '?>
<!DOCTYPE   html
                PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml "   xml:lang= "en "   lang= "en ">
<head>
  <meta   http-equiv= "content-type "   content= "application/vnd.wap.xhtml+xml;charset=UTF-8 "/>
        <title> 文件上传 </title>
</head>
<body>
<form   name= "form1 "   method= "post "   action= "up.jsp "   enctype= "multipart/form-data ">
        密码: <input   type= "text "   name= "pass "/> <br/>
        <input   type= "file "   name= "file1 "/>
        <input   type= "submit "   name= "submit "   value= "·   提交   · "/>
</form>
</body>
</html>
---------------------------------------------
<%@   page   import= "org.apache.commons.fileupload.FileItem "   %>
<%@   page   import= "org.apache.commons.fileupload.servlet.ServletRequestContext "   %>
<%@   page   import= "java.io.File "   %>
<%@   page   contentType= "text/vnd.wap.wml;charset=UTF-8 "   language= "java "   %>
<jsp:useBean   id= "fUpload "   scope= "page "   class= "org.apache.commons.fileupload.FileUpload "/>
<!DOCTYPE   wml   PUBLIC   "-//WAPFORUM//DTD   WML   1.1//EN "   "http://www.wapforum.org/DTD/wml_1.1.xml ">
<wml>
        <card>
                <p>
<%
        try   {
                String   path   =   request.getSession().getServletContext().getRealPath( "/ ");
                out.println(path);
        out.println(request.getParameterMap());
                fUpload.setSizeMax(1000000);
                out.println( "hi.nihao1 ");
                fUpload.setFileItemFactory(new   org.apache.commons.fileupload.disk.DiskFileItemFactory());
                out.println( "hi.nihao2 ");
                java.util.List   items   =   fUpload.parseRequest(new   ServletRequestContext(request));
                out.println( "hi.nihao3 ");
                FileItem   fi   =   (FileItem)   items.get(1);
                out.println( "hi.nihao4 ");
                File   uploadFile   =   new   File(path+ "/ "+fi.getName());
                out.println( "hi.nihao5 ");
                fi.write(uploadFile);
                out.println( "hi.nihao6 ");
                out.println(request.getSession().getServletContext().getRealPath( "/ "));
        }   catch   (Exception   ex)   {
                ex.printStackTrace(System.out);
                out.println( "ERROR~! "+ex);
        }
%>
                </p>
      </card>
        </wml>

原创粉丝点击