wap2.0 xhtml 文件上传代码记录一下~~。cmwap测试不行,cmnet可以。

xhtml页面:

 

<? 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 >

 后台jsp,用的是apache的上传组件 commons-fileupload-1.1.1.jar

 

<%@ 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>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值