当前位置:编程学习 > JAVA >>

java-张侃— struts2-上传功能

   文件上传是web应用中一种常见的功能,有着很广泛的作用,下面我就分享一下我写的一个struts2上传案例,通过案例,我们可以快速掌握struts2的上传-----------------------------------
  先写好上传所需的jsp页面:
      上传页面(index.jsp)-----
[html]  
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>    
<%    
    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>文件上传</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">  
    -->    
</head>    
    
<body>    
    <div align="center">    
        <h3>文件上传</h3>    
        <form action="${pageContext.request.contextPath}/csdn/UploadAction_upload.action" method="post" enctype="multipart/form-data">    
            上传文件:<input type="file" name="upload"><br>    
            上传文件:<input type="file" name="upload"> <br />     
            <input type="submit" value="上传" />    
        </form>    
    </div>    
</body>    
</html>    
 
 
[html]  
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
<%  
    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>文件上传</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"> 
    -->  
</head>  
  
<body>  
    <div align="center">  
        <h3>文件上传</h3>  
        <form action="${pageContext.request.contextPath}/csdn/UploadAction_upload.action" method="post" enctype="multipart/form-data">  
            上传文件:<input type="file" name="upload"><br>  
            上传文件:<input type="file" name="upload"> <br />   
            <input type="submit" value="上传" />  
        </form>  
    </div>  
</body>  
</html>  
 
        上传成功页面(sc.jsp)-----
[html]  
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>    
<%@ taglib uri="/struts-tags"  prefix="s" %>    
<%    
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>上传成功页面</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">  
    -->    
  </head>    
      
  <body>    
       <div align="center">    
             <h3>文件上传成功!!!!</h3>     
       </div> &n
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,