<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-21  評(píng)論-29  文章-0  trackbacks-0
    前言:好久沒有發(fā)新隨筆了,不是沒有在學(xué)習(xí),而是這個(gè)月BRAS用得太猛了,后面幾天都沒網(wǎng)上了!好了,言歸正傳,用一個(gè)小工程總結(jié)一下最近學(xué)習(xí)Struts2的心得體會(huì)。
    開發(fā)環(huán)境:jdk1.6 + tomcat6.0.14 + Myeclipse6.0 + Struts2.0.14 + commons-fileupload-1.2.1 + commons-io-1.4
    學(xué)習(xí)教程:風(fēng)中葉 浪曦_Struts2應(yīng)用開發(fā)系列
    小項(xiàng)目需求分析或?qū)崿F(xiàn)的功能:
    (1).用戶只有輸入正確的邀請(qǐng)碼之后才能進(jìn)行注冊(cè),否則填寫注冊(cè)信息之后提交沒有反應(yīng),還會(huì)停留在注冊(cè)頁面。
    (2).用戶注冊(cè)之后可以上傳文件,也可以下載其中的文件。
    分析:struts2并沒有實(shí)現(xiàn)文件的上傳和下載,我們需要到apache網(wǎng)站去下載commons-fileupload-1.2.1 和 commons-io-1.4 ,并把其中的核心jar包導(dǎo)入到工程。我們可以使用攔截器來實(shí)現(xiàn)功能(1)。

    具體步驟:
    1.新建web項(xiàng)目 命名為struts2demo


    2.向工程中導(dǎo)入所需要的jar包 必要的jar包有七個(gè)


    3.在web.xml文件中注冊(cè)struts2
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" 
        xmlns
    ="http://java.sun.com/xml/ns/j2ee" 
        xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation
    ="http://java.sun.com/xml/ns/j2ee 
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    >
      
      
    <filter>
         
    <filter-name>struts2</filter-name>
         
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> 
      
    </filter>
     
      
    <filter-mapping>
         
    <filter-name>struts2</filter-name>
         
    <url-pattern>/*</url-pattern>
      
    </filter-mapping>
      
    </web-app>

    4.編寫輸入邀請(qǐng)碼的JSP頁面invite.jsp
    <%@ page language="java" contentType="text/html; charset=GBK"
        pageEncoding
    ="GBK"
    %>
    <%@ taglib prefix="s" uri="/struts-tags" %>   

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head><title>驗(yàn)證碼校驗(yàn)</title></head>
    <body>   
        
    <table align="center" width="60%"><tr><td style="color:red"><s:fielderror/></td></tr></table>   
        
    <form action="invite.action" method="post">
            請(qǐng)輸入您的驗(yàn)證碼:
    <br>
           
    <input type="text" name="invitedcode"><br>
           
    <input type="submit" value="提交驗(yàn)證碼">
           
    <input type="reset" value="重新輸入">   
        
    </form>   
    </body>
    </html>

    5.在Tomcat的server.xml中加入工程

    6.啟動(dòng)Tomcat服務(wù)器 測(cè)試當(dāng)前所做是否有錯(cuò)誤


    以上表明當(dāng)前設(shè)置沒有錯(cuò)誤!
    7.在src下新建com.demo.action包,并在其中新建InviteAction類,此類要繼承ActionSupport類


    package com.demo.action;

    import java.util.Map;
    import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.ActionSupport;

    public class InviteAction extends ActionSupport {
        
    private String invitedcode;

        
    public String getInvitedcode() {
            
    return invitedcode;
        }


        
    public void setInvitedcode(String invitedcode) {
            
    this.invitedcode = invitedcode;
        }


        @Override
        
    public String execute() throws Exception {
            
    if("220081078".equals(this.getInvitedcode())){       
                
    return SUCCESS;
            }

            
    else{
                
    this.addFieldError("invitedcode""輸入的邀請(qǐng)碼不正確!請(qǐng)?jiān)俅屋斎耄?/span>");
                
    return INPUT;
            }

        }

    }


    類中規(guī)定只有輸入的驗(yàn)證碼為220081078,才能進(jìn)入到注冊(cè)頁面,否則會(huì)出現(xiàn)錯(cuò)誤的提示信息并回到原頁面繼續(xù)輸入。

    8.在src下新建struts.xml文件,在struts.xml文件中對(duì)InviteAction進(jìn)行注冊(cè)
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd"
    >

    <struts>

        
    <package name="struts2demo" extends="struts-default">

            
    <action name="invite" class="com.demo.action.InviteAction">           
                
    <result name="input">/invite.jsp</result>
                
    <result name="success">/register.jsp</result>
            
    </action>    
             
        
    </package>
        
    </struts>

    9.新建register.jsp頁面,并加入如下代碼
    <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
    <%@ taglib prefix="s" uri="/struts-tags" %>

    <%
    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>
       
    <title>注冊(cè)頁面</title>

        
    <script type="text/javascript">
            
    function validate(){
               
    var usernameValue = document.getElementById("usernameId").value;
               
    var passwordValue = document.getElementById("passwordId").value;
               
    var repasswordValue = document.getElementById("repasswordId").value;
               
               
    if(usernameValue.length == 0){
                   alert(
    "用戶名不能為空!");
                   
    return false;
               }

               
    else if(usernameValue.length < 6 || usernameValue.length > 16){
                   alert(
    "用戶名只能由6-16位字母和數(shù)字組成!");
                   
    return false;
               }

               
               
    if(passwordValue.length == 0){
                   alert(
    "密碼不能為空!");
                   
    return false;
               }

               
    else if(passwordValue.length < 6 || passwordValue.length > 16){
                   alert(
    "用戶名只能由6-16位字母和數(shù)字組成!");
                   
    return false;
               }

               
               
    if(passwordValue != repasswordValue){
                   alert(
    "兩次輸入的密碼不一致!");
                   
    return false;
               }

               
               
    return true;
            }

        
    </script>

      
    </head>
      
      
    <body>

          
    <table align="center" width="60%"><tr><td style="color:green"><s:fielderror/></td></tr></table>

          
    <s:form action="register" theme="simple" method="post">
          
          
    <table align="center" width="40%" border="2">
             
    <tr><td>*用戶名:</td><td> <s:textfield name="username" id="usernameId"></s:textfield> </td></tr>
             
    <tr><td>*密碼:</td><td> <s:password name="password" id="passwordId"></s:password> </td></tr>
             
    <tr><td>*重復(fù)密碼:</td><td> <s:password name="repassword" id="repasswordId"></s:password> </td></tr>
             
    <tr><td>年齡:</td><td> <s:textfield name="age"></s:textfield> </td></tr>
             
    <tr><td>生日:</td><td> <s:textfield name="birthday"></s:textfield> </td></tr>
             
    <tr><td> <s:submit value="注冊(cè)" onclick="validate()"></s:submit></td><td><s:reset value="重填"></s:reset> </td></tr>
                   
          
    </table>
          
    </s:form>
       
      
    </body>
    </html>
    其中腳本validate()方法對(duì)輸入進(jìn)行客戶端的驗(yàn)證,如果沒有輸入必填項(xiàng)(用戶名和密碼)或輸入的長(zhǎng)度超過限制,都會(huì)提示相應(yīng)的錯(cuò)誤信息。

    10.對(duì)以上所做工作進(jìn)行測(cè)試
    如果輸入錯(cuò)誤的邀請(qǐng)碼 如2200810888 則顯示結(jié)果如下


    如果輸入正確的邀請(qǐng)碼 如220081078 則轉(zhuǎn)入到注冊(cè)頁面 測(cè)試成功!


    11.在action包中創(chuàng)建RegisterAction類 并編寫如下代碼
    package com.demo.action;

    import java.util.Calendar;
    import java.util.Date;

    import com.opensymphony.xwork2.ActionSupport;

    public class RegisterAction extends ActionSupport {
        
    private String username;
        
    private String password;
        
    private String repassword;
        
    private int age;
        
    private Date birthday;

        
    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;
        }


        
    public String getRepassword() {
            
    return repassword;
        }


        
    public void setRepassword(String repassword) {
            
    this.repassword = repassword;
        }


        
    public int getAge() {
            
    return age;
        }


        
    public void setAge(int age) {
            
    this.age = age;
        }


        
    public Date getBirthday() {
            
    return birthday;
        }


        
    public void setBirthday(Date birthday) {
            
    this.birthday = birthday;
        }


        @Override
        
    public String execute() throws Exception {
            
            
    return SUCCESS;
        }


        @Override
        
    public void validate() {
            
    if(null == username || username.length()<6 || username.length()>16){
                
    this.addActionError("用戶名應(yīng)該由6-10位字母和數(shù)字組成");
              }

            
    if(null == password || password.length()<6 || password.length()>16){
                    
    this.addActionError("密碼應(yīng)該由6-10位字母和數(shù)字組成");
              }

            
    else if(!(repassword.equals(password))){
                    
    this.addActionError("兩次輸入密碼不一致!");
              }

            
    if(age<0 || age>150){
                    
    this.addActionError("年齡應(yīng)該在0-150之間!");
              }

            
        }
        
    }

     其中validate()方法對(duì)輸入進(jìn)行服務(wù)器端的驗(yàn)證,以提高安全性。

    12.在struts.xml文件中對(duì)RegisterAction進(jìn)行注冊(cè) 在package下加入如下代碼

    <action name="register" class="com.demo.action.RegisterAction">           
                
    <result name="input">/register.jsp</result>
                
    <result name="success">/registersuccess.jsp</result>
            
    </action>

    13.編寫registersuccess.jsp頁面
    <%@ page language="java" contentType="text/html; charset=GBK"
        pageEncoding
    ="GBK"
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>

    <title>注冊(cè)成功</title>
    </head>
    <body>
        恭喜您已經(jīng)注冊(cè)成功!
    <br>
        一下是您的注冊(cè)信息:
    <br>
        用戶名:${requestScope.username}
    <br>
        密碼:${requestScope.password}
    <br>
        年齡:${requestScope.age}
    <br>
        生日:${requestScope.birthday}
    <br>

        
    <href="upload.jsp">開始上傳文件</a>
    </body>
    </html>

    14.對(duì)上述工作進(jìn)行測(cè)試
    如果進(jìn)行不合法的注冊(cè) 如沒有填入必填項(xiàng)或者輸入長(zhǎng)度不合法 會(huì)出現(xiàn)相關(guān)錯(cuò)誤提示信息


    如果輸入合法注冊(cè)信息,將轉(zhuǎn)到注冊(cè)成功頁面。


    15.編寫文件上傳頁面upload.jsp代碼
    <%@ page language="java" contentType="text/html; charset=GBK"
        pageEncoding
    ="GBK"
    %>
    <%@ taglib prefix="s" uri="/struts-tags"%>

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>上傳文件頁面</title>

       
    <script type="text/javascript">
          
    function addMore(){
             
    var td = document.getElementById("more");
             
    var br = document.createElement("br");
             
    var input = document.createElement("input");
             
    var button = document.createElement("input");
             input.type 
    = "file";
             input.name 
    = "file";
             button.type
    ="button";
             button.value
    ="Remove";
             
             button.onclick 
    = function(){
                td.removeChild(br);
                td.removeChild(input);
                td.removeChild(button);
             }

             
             
             td.appendChild(br);
             td.appendChild(input);
             td.appendChild(button);
          
          }

       
       
    </script>


    </head>
    <body>
        
         
    <table align="center" width="60%"><tr><td style="color:green"><s:fielderror/></td></tr></table>
        
         
    <s:form action="upload" theme="simple" enctype="multipart/form-data" method="post">
          
          
    <table align="center" width="50%" border="2">
          
             
    <tr><td>用戶名:</td><td> <s:textfield name="username"></s:textfield> </td></tr>
             
    <tr><td>密碼:</td><td> <s:password name="password"></s:password> </td></tr>
             
    <tr><td>選擇文件:</td>  <td id="more"><s:file name="file"></s:file><input type="button" value="上傳更多" onclick="addMore()"></td> </tr>
             
    <tr><td><s:submit value=" 全部上傳 "></s:submit></td></tr>
                   
          
    </table>
          
    </s:form>
        
    </body>
    </html>
      該頁面允許用戶上傳足夠多的文件。點(diǎn)擊“上傳更多...”按鈕一次會(huì)添加一個(gè)上傳文件textfield,點(diǎn)擊‘Remove’按鈕可以消去該行。

    16.編寫UploadAction類代碼 將文件上傳到upload文件夾
    package com.demo.action;

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.List;

    import org.apache.struts2.ServletActionContext;

    import com.opensymphony.xwork2.ActionSupport;

    public class UploadAction extends ActionSupport {
        
    private String username;
        
    private String password;
        
    private List<File> file;
        
    private List<String> fileFileName;
        
    private List<String> fileContentType;
        
    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;
        }

        
        
    public List<File> getFile() {
            
    return file;
        }

        
    public void setFile(List<File> file) {
            
    this.file = file;
        }

        
    public List<String> getFileFileName() {
            
    return fileFileName;
        }

        
    public void setFileFileName(List<String> fileFileName) {
            
    this.fileFileName = fileFileName;
        }

        
    public List<String> getFileContentType() {
            
    return fileContentType;
        }

        
    public void setFileContentType(List<String> fileContentType) {
            
    this.fileContentType = fileContentType;
        }

        
        @Override
        
    public String execute() throws Exception {
            
            
            
    for(int i = 0;i<file.size();i++){
                InputStream is 
    = new FileInputStream(file.get(i));
                
                String root 
    = ServletActionContext.getRequest().getRealPath("/upload");
                
                File destFile 
    = new File(root,this.getFileFileName().get(i));
                
                OutputStream os 
    = new FileOutputStream(destFile);
                
                
    byte[] buffer = new byte[400];
                
    int length = 0 ;
                
    while((length = is.read(buffer)) > 0){
                    os.write(buffer, 
    0, length);
                }

                
                is.close();
                os.close();
            }

            
            
    return SUCCESS;
        }

        
    }


    17.在struts.xml文件中對(duì)UploadAction進(jìn)行注冊(cè)
         <action name="upload" class="com.demo.action.UploadAction">
                
    <result name="success">/uploadsuccess.jsp</result>
                
    <result name="input">/upload.jsp</result>
                
    <interceptor-ref name="fileUpload">
                    
    <param name="maximumSize">4096000</param>
                    
    <param name="allowedTypes">application/vnd.ms-powerpoint</param>
                
    </interceptor-ref> 
                
    <interceptor-ref name="defaultStack"></interceptor-ref>
            
    </action>
     上傳文件時(shí)會(huì)用到內(nèi)部的fileUpload攔截器 其中對(duì)上傳文件的大小和類型進(jìn)行了限制 如上也許上傳最大文件為4000K,文件類型只能為ppt類型。

    18.對(duì)上傳文件是的錯(cuò)誤信息進(jìn)行改進(jìn),系統(tǒng)提供的錯(cuò)誤信息(如文件大小或類型不合法)可讀性很差。
        在struts.xml中加入如下語句 
    <constant name="struts.custom.i18n.resources" value="message"></constant>
        
        
    <constant name="struts.i18n.encoding" value="gbk"></constant>
       第一句是配置錯(cuò)誤信息message.properties,第二句是對(duì)上傳文件過程中的中文亂碼進(jìn)行更正。
       在src目錄下新建文件message.properties ,文件內(nèi)容為
    struts.messages.error.content.type.not.allowed=\u4e0a\u4f20\u7684\u6587\u4ef6\u7c7b\u578b\u4e0d\u5141\u8bb8 \u8bf7\u91cd\u8bd5
    struts.messages.error.file.too.large=\u4e0a\u4f20\u6587\u4ef6\u7684\u5927\u5c0f\u8d85\u8fc7\u9650\u5236
      右邊的編碼可以通過Java提供的native2ascii進(jìn)行轉(zhuǎn)換。

    19.編寫download.jsp頁面
    <%@ page language="java" contentType="text/html; charset=GBK"
        pageEncoding
    ="GBK"
    %>
        
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>

    <title>文件下載</title>
    </head>
    <body>
        歡迎來到下載頁面!
    <br>
       
    <s:a href="/struts2/download.action">點(diǎn)擊下載</s:a>

    </body>
    </html>

      20.編寫DownloadAction類代碼 假設(shè)我們要下載的是upload文件夾下的Struts2.ppt文件

     

    package com.demo.action;

    import java.io.InputStream;

    import org.apache.struts2.ServletActionContext;

    import com.opensymphony.xwork2.ActionSupport;

    public class DownloadAction extends ActionSupport {
         
        
    public InputStream getDownloadFile(){
            
    return ServletActionContext.getServletContext().getResourceAsStream("/upload/Struts2.ppt");
            
        }


        @Override
        
    public String execute() throws Exception {
            
    return SUCCESS;
        }

        
        
    }




     

    21.在struts.xml文件中對(duì)DownloadAction進(jìn)行注冊(cè) 要注意其中的參數(shù)名稱

     <action name="download" class="com.demo.action.DownloadAction"> 
                
    <result name="success" type="stream">
                   
    <param name="contentType">application/vnd.ms-powerpoint</param>
                   
    <param name="contentDisposition">filename="Struts2.ppt"</param>
                   
    <param name="inputName">downloadFile</param>
                
    </result>
            
    </action>


     22.對(duì)以上步驟進(jìn)行測(cè)試

    上傳文件類型不合法


    上傳合法內(nèi)容,如我們上傳三個(gè)ppt文件 則能成功





    點(diǎn)擊到下載頁面下載文件

    23.實(shí)現(xiàn)邀請(qǐng)碼功能 以上并沒有實(shí)現(xiàn)邀請(qǐng)碼的功能,即用戶可以直接進(jìn)入到注冊(cè)頁面進(jìn)行注冊(cè)。我們需要編寫一個(gè)攔截器實(shí)現(xiàn)該功能。
    (1)編寫InviteInterceptor攔截器代碼
       
    package com.demo.interceptor;

    import java.util.Map;

    import com.opensymphony.xwork2.Action;
    import com.opensymphony.xwork2.ActionInvocation;
    import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

    public class InviteInterceptor extends AbstractInterceptor {

        @Override
        
    public String intercept(ActionInvocation invocation) throws Exception {
            Map map 
    = invocation.getInvocationContext().getSession();
            
    if(map.get("invitedcode"== null){
                
    return Action.INPUT;
            }
    else{
                
    return invocation.invoke();
            }

        }


    }


    (2)改寫InviteAction的execute()方法 加入如下語句
        
    (3)在struts.xml中注冊(cè)攔截器 并在register的action中加入攔截器
       最終struts.xml的代碼
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd"
    >

    <struts>
        
    <constant name="struts.custom.i18n.resources" value="message"></constant>
        
        
    <constant name="struts.i18n.encoding" value="gbk"></constant>
        
    <constant name="struts.multipart.saveDir" value="/upload"></constant>
      
        
    <package name="struts2demo" extends="struts-default">
        
            
    <interceptors>            
               
    <interceptor name="invite" class="com.demo.interceptor.InviteInterceptor"></interceptor>
            
    </interceptors>    
            
           

            
    <action name="invite" class="com.demo.action.InviteAction">           
                
    <result name="input">/invite.jsp</result>
                
    <result name="success">/register.jsp</result>
            
    </action>    
            
            
    <action name="register" class="com.demo.action.RegisterAction">           
                
    <result name="input">/register.jsp</result>
                
    <result name="success">/registersuccess.jsp</result>
                
                
    <interceptor-ref name="invite"></interceptor-ref>
                
    <interceptor-ref name="defaultStack"></interceptor-ref>
            
    </action>
            
            
    <action name="upload" class="com.demo.action.UploadAction">
                
    <result name="success">/uploadsuccess.jsp</result>
                
    <result name="input">/upload.jsp</result>
                
    <interceptor-ref name="fileUpload">
                    
    <param name="maximumSize">4096000</param>
                    
    <param name="allowedTypes">application/vnd.ms-powerpoint</param>
                
    </interceptor-ref> 
                
    <interceptor-ref name="defaultStack"></interceptor-ref>
            
    </action>
            
             
    <action name="download" class="com.demo.action.DownloadAction"> 
                
    <result name="success" type="stream">
                   
    <param name="contentType">application/vnd.ms-powerpoint</param>
                   
    <param name="contentDisposition">filename="Struts2.ppt"</param>
                   
    <param name="inputName">downloadFile</param>
                
    </result>
            
    </action>
             
        
    </package>
        
    </struts>

    24.最后的測(cè)試
    如果沒有進(jìn)行邀請(qǐng)碼的驗(yàn)證 直接進(jìn)入到注冊(cè)頁面進(jìn)行注冊(cè) 將不成功。達(dá)到項(xiàng)目需求。

    總結(jié):這是最近三天學(xué)習(xí)的結(jié)果,很喜歡風(fēng)中葉老師的講解。他沒有給我們代碼,卻每一步都講得很仔細(xì),還帶著我們一步步地看相關(guān)的幫助文檔,會(huì)繼續(xù)支持風(fēng)中葉老師的!開發(fā)還是要自己多看看各種文檔,這樣才能學(xué)習(xí)到正宗的知識(shí)!

    由于隨筆附件大小有限制 上傳的代碼中刪除了struts2的5個(gè)jar包 可自行加入
    本隨筆代碼 代碼

    posted on 2009-05-26 21:49 特立獨(dú)行 閱讀(17518) 評(píng)論(27)  編輯  收藏 所屬分類: Struts框架

    評(píng)論:
    # re: struts2實(shí)現(xiàn)文件上傳的下載 2009-05-27 16:49 | 代號(hào)zzy
    兄弟,贊一個(gè)。  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳的下載[未登錄] 2009-05-27 17:06 | EricFan
    大哥,什么叫做文件上傳的下載?  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳的下載 2009-05-30 00:16 | 事發(fā)當(dāng)時(shí)
    就一個(gè)上傳下載文件,竟然讓你搞了這么一大堆垃圾代碼,攔截器都是現(xiàn)成的,一個(gè)action ,5,6行代碼足以,洋洋撒薩!  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳的下載 2009-05-30 08:50 | 特立獨(dú)行
    @事發(fā)當(dāng)時(shí)
    本人菜鳥而已 只是把最近的學(xué)習(xí)內(nèi)容串聯(lián)在一起 復(fù)習(xí)一下 沒有別的  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳的下載 2009-05-30 18:20 | gyl868
    謝謝樓主分享,很詳細(xì)適合我這種初學(xué)者,希望多多發(fā)此類帖子喲,我會(huì)常來看的,有個(gè)問題,使用攔截器后還是可以不通過驗(yàn)證頁面直接進(jìn)入register.jsp頁可提交成功,不知道為何  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳的下載 2009-06-01 17:07 | 特立獨(dú)行
    @gyl868
    可能我配置的時(shí)候錯(cuò)誤了 我有空再看看  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳的下載[未登錄] 2009-07-19 11:14 | skyman
    這些截圖真的是由這些代碼產(chǎn)生的嗎?有些地方是錯(cuò)的,如RegisterAction里面的validate方法中addActionError,但在相應(yīng)的jsp中卻用的是fielderror...  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳的下載[未登錄] 2009-08-17 14:16 | 小強(qiáng)
    撒旦法撒旦法  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳的下載 2009-12-17 22:50 |
    NB的人都滾一邊去,人家分享個(gè)東西,看把TM你給牛的!

    腦殘!

    看不懂什么意思還不如去。。。

    真2.。。  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳的下載 2009-12-17 22:51 |
    NB的人都滾一邊去,人家分享個(gè)東西,看把TM你給牛的!

    腦殘!

    看不懂什么意思還不如去死!。。。  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳的下載 2010-05-07 14:16 | 一個(gè)人
    寫的不錯(cuò),基本上跟著樓主做出來了,謝謝  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載 2010-07-25 01:16 | 黃文龍
    謝謝樓主 學(xué)習(xí)了  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載[未登錄] 2010-09-26 13:22 |
    很好!  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載[未登錄] 2010-09-26 15:49 |
    我是菜鳥,按你的步驟走 由錯(cuò)誤 提示我找不到系統(tǒng)指定的路徑  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載 2011-01-20 10:28 | weiythi
    不錯(cuò) 學(xué)習(xí)了  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載 2011-01-27 09:51 | chenwei
    fsdfdsfdsfs  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載 2011-06-14 09:52 | 游仞
    下載功能不行  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載[未登錄] 2011-07-14 16:34 | 鄭少文
    @事發(fā)當(dāng)時(shí)
    可以把你說的方法給我看看么??

    javajacob@163.com先謝過。  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載 2012-03-26 19:32 | 方式
    你是北京圣思園的吧,一點(diǎn)新意沒有  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載 2012-04-09 15:42 | ry
    步驟不全啊~uploadsuccess.jsp就沒有說怎么建啊  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載 2012-04-25 14:04 | fdsf
    # re: struts2實(shí)現(xiàn)文件上傳和下載[未登錄] 2012-05-25 18:01 | hh
    我運(yùn)行下載頁面時(shí)出錯(cuò)啊!怎么改?  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載 2012-05-25 23:37 | pppppppppp
    大俠 ……怎么實(shí)現(xiàn)點(diǎn)一個(gè)文件下載一個(gè)文件,而不是固定的文件?  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載 2012-09-06 11:27 | 采用
    配置的文件 有關(guān)鍵字, 把a(bǔ)ction 中的name 換下就可以了 @陳  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載 2012-12-04 18:54 | 邊城
    怎么將上傳的東西在頁面上顯示出來啊  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載 2012-12-07 16:32 | 你這代碼量有點(diǎn)多
    你這代碼量有點(diǎn)多,STRUTS2封裝好了,頂多15行搞定  回復(fù)  更多評(píng)論
      
    # re: struts2實(shí)現(xiàn)文件上傳和下載[未登錄] 2012-12-20 21:25 | 小菜
    下載做來直接就在頁面把文件打開了。。  回復(fù)  更多評(píng)論
      
    主站蜘蛛池模板: 老司机午夜在线视频免费| 成人福利在线观看免费视频| 色噜噜AV亚洲色一区二区| 在线免费观看国产| 九九九国产精品成人免费视频| 亚洲理论精品午夜电影| 亚洲国产一级在线观看| 在线观看免费a∨网站| 久久综合给合久久国产免费 | www永久免费视频| 亚洲精品无码av片| 亚洲国产精品yw在线观看| 亚洲国产成人高清在线观看| 亚洲av无码乱码在线观看野外| 大学生一级特黄的免费大片视频| 日韩精品人妻系列无码专区免费| 深夜福利在线视频免费| 亚洲Av永久无码精品一区二区| 激情亚洲一区国产精品| 色九月亚洲综合网| 精品国产无限资源免费观看| 日本免费电影一区二区| 成人免费av一区二区三区| 一边摸一边桶一边脱免费视频| 偷自拍亚洲视频在线观看| 亚洲成a人片在线观看天堂无码| 一本色道久久88—综合亚洲精品 | a级毛片毛片免费观看永久| 国产免费一区二区三区免费视频| MM1313亚洲精品无码久久| 亚洲а∨精品天堂在线| 亚洲欧美综合精品成人导航| 2020国产精品亚洲综合网| 99999久久久久久亚洲| 色在线亚洲视频www| 亚洲日本成本人观看| 亚洲精品9999久久久久无码| 亚洲精品第一国产综合亚AV| 亚洲日韩av无码中文| 激情小说亚洲图片| 一个人看的在线免费视频|