struts2 struts2中的流接收與流傳送

2021-09-08 12:52:30 字數 1407 閱讀 5393

【流接收】

如今舉乙個傳公鑰的樣例。struts2用乙個action接收key,而key就是用http二進位制流傳過來的。

配置檔案struts.xml寫起來非常easy:

/web-inf/content/success.jsp

/web-inf/content/error.jsp

僅僅是簡單的指定了用public string key()方法來處理這個action,action中用servlet的request讀出流

public class publickeyaction extends actionsupport catch (exception e) }}

為了配合測試,貼上client發請求的**。

uconnection.setdooutput(true);

outputstream ostream = uconnection.getoutputstream();

// 生成key

keypairgenerator pairgenerator = keypairgenerator.getinstance("rsa");

securerandom random = new securerandom();

pairgenerator.initialize(keysize,random);

keypair keypair = pairgenerator.generatekeypair();

try (objectoutputstream out = new objectoutputstream(ostream);) catch (exception e)

uconnection.getinputstream();

} catch (malformedurlexception e) catch (ioexception e) catch (nosuchalgorithmexception e) }}

【流傳送】流傳送一般用於server公布流**。像中文名的就能夠用流傳送的方式提供,而不用改動tomcat的配置

struts.xml中,相應的流傳送action要配置成stream模式

inputpath">/web-inf/androidversion/seeplant.apk

targetfile

filename="seeplantpack.apk"

4096

action非常easy

private string inputpath;

public void setinputpath(string inputpath)

// 注意這裡的入口方法的返回值是inputstream介面型別

public inputstream gettargetfile() throws exception

}

Struts 2 Struts2 詳細配置

全域性配置 配置在packe 中,所有 action 的上面。頁面 頁面 區域性結果優先順序高於全域性。異常資訊配置 404異常 500異常 web.xml 配置 404 error.jsp 500 error.jsp 包 package 配置 所有的action 配置,都必須在包中。jsp頁面路徑...

Struts2字尾 深入Struts2

一 將action字尾變成html字尾 xmlversion 1.0 encoding utf 8 doctype struts public apache software foundation dtd struts configuration 2.1 en struts include file...

Struts2中checkboxlist標籤的使用

selectedproducts name product.id list products listvalue name listkey id value 這裡分兩類,首先明確value的值應該是乙個list,用來顯示checkbox內那些需要先打勾 一類,當value的值是是乙個list bea...