日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Struts2 随笔1

發布時間:2025/5/22 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Struts2 随笔1 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
配置攔截器 <interceptors><interceptor-stack name="mystack"><!-- 默認的攔截器 --><interceptor-ref name="struts-default"></interceptor-ref><!--查看每個運行action時間 --><interceptor-ref name="timer"></interceptor-ref></interceptor-stack></interceptors><!-- 修改默認攔截器(要在action之前) --><default-interceptor-ref name="mystack"></default-interceptor-ref>

?

在struts.xml文件中,有時候打一個 < 卻沒有提示,原因是因為沒有連接互聯網,訪問不到"http://struts.apache.org/dtds/struts-2.3.dtd"這個路徑 解決方法:1、連接到互聯網,工具會自動下載使用2、在MyEclipse中配置一下 配置步驟如下: Window---?Preferences--?MyEclipse Enterprise …. ---?XML-----?XML Catalog --? 然后點擊Add按鈕,添加文件。Location 添加的是struts-2.3.dtd文件的路徑,Key Type選擇URL,KEY中的內容為http://struts.apache.org/dtds/struts-2.3.dtd,選擇OK. 注意:在配置完成之后,struts.xml文件中可能會有一個紅叉,按一下回車鍵,然后在保存一下就可以了

?

<!--公共的跳轉 --><global-results><result name="logins" type="redirectAction"><param name="actionName">login</param><!-- login?code=1001 --><param name="code">1001</param></result></global-results>

?

文件下載 <action name="download" class="com.peng.action.UserAction" method="download"><result type="stream">
            //文件類型<param name="contentType">${fileType}</param>
            //文件大小<param name="contentLength">${fileLength}</param><param name="contentDisposition">attachment;filename="${fileName}"</param><param name="contentCharSet">UTF-8</param>
            //指向getInputstream<param name="inputName">inputstream</param></result></action>//actionpublic String download() {return SUCCESS;}public InputStream getInputstream() throws FileNotFoundException {fileName = "zhangqingfeng.doc";File file = new File("E:/Download/",fileName);fileType = map.get(file.getName().substring(file.getName().trim().lastIndexOf(".")));fileLength = file.length();return new FileInputStream(file);}

?

//文件上傳 <action name="upload" class="com.peng.action.UserAction" method="upload"><result type="redirectAction"><param name="actionName">home</param></result></action>//action public String upload() throws Exception{System.out.println("Desc: " + desc);//獲取文件名稱為臨時文件的名稱System.out.println("Pic Name: " + pic.getName());System.out.println("Pic length :" + pic.length());//獲取文件真正的文件名System.out.println("File Name:" + picFileName);System.out.println("文件類型:" + picContentType);InputStream input = new FileInputStream(pic);OutputStream out = new FileOutputStream(new File("E:/Download/",UUID.randomUUID().toString()+picFileName.substring(picFileName.lastIndexOf("."))));byte[] buffer = new byte[1024]; int len = -1;while ((len=input.read(buffer))!=-1) {out.write(buffer,0,len);}out.flush();out.close();input.close();return SUCCESS;}

?

轉載于:https://www.cnblogs.com/fudapeng/p/3805396.html

總結

以上是生活随笔為你收集整理的Struts2 随笔1的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。