java實(shí)例代碼下載,java實(shí)例大全

求一個(gè)JAVA∶貓狗案例代碼

代碼如下

網(wǎng)站制作、建網(wǎng)站找專業(yè)網(wǎng)絡(luò)公司創(chuàng)新互聯(lián)建站:定制網(wǎng)站、模板網(wǎng)站、仿站、微信小程序定制開發(fā)、軟件開發(fā)、app軟件開發(fā)等。做網(wǎng)站價(jià)格咨詢創(chuàng)新互聯(lián)建站:服務(wù)完善、10年建站、值得信賴!網(wǎng)站制作電話:13518219792

abstract class Dongwu {

void chi(){

System.out.println("吃");

}

}

interface Tiao{

void tiao();

}

interface Suan{

void suan();

}

class Mao extends Dongwu implements Tiao{

public void tiao() {

System.out.println("貓會(huì)跳高");

}

}

class Gou extends Dongwu implements Suan{

public void suan() {

System.out.println("狗會(huì)算數(shù)");

}

}

如果有幫助到你,請(qǐng)點(diǎn)擊采納

誰(shuí)能提供給我weblogic上跑jaas的實(shí)例

這有個(gè) jaas tomcat的實(shí)例, 先看下吧:

準(zhǔn)備文件和目錄

創(chuàng)建文件login.jsp和error.jsp

login.jsp的內(nèi)容

html

head

meta HTTP-EQUIV="Content-Type" Content="text-html; charset=gbk"

titlelogin/title

/head

body

form method="POST" action="j_security_check"

姓名:input type="text" name="j_username"/

br/

密碼:input type="password" name="j_password"/

br/

input type="submit" value="提交"/

/form

/body

/html

在根目錄下創(chuàng)建目錄web,在新建的目錄下創(chuàng)建一個(gè)文件index.jsp,內(nèi)容如下

html

head

meta http-equiv="Content-Type"

content="text/html; charset=GBK"

titleApache-Axis/title

/head

body bgcolor="#FFFFFF"

request.FORM_AUTH:%=request.FORM_AUTH%br/

request.getRemoteUser():%=request.getRemoteUser()%br/

/body

/html

設(shè)置配置文件

在web.xml中添加以下內(nèi)容

web-app

...

security-constraint

!-- Sample Security Constraint --

web-resource-collection

!-- We're going to protect this resource and make it available only to users in "role1". --

web-resource-nameprotected-resources/web-resource-name

url-pattern/web/*/url-pattern

http-methodHEAD/http-method

http-methodGET/http-method

http-methodPOST/http-method

http-methodPUT/http-method

http-methodDELETE/http-method

/web-resource-collection

!-- NOTE: This role names will be retrieved by Josso using the propper identity store. --

auth-constraint

role-namerole1/role-name

/auth-constraint

user-data-constraint

transport-guaranteeNONE/transport-guarantee

/user-data-constraint

/security-constraint

login-config

auth-methodFORM/auth-method

form-login-config

form-login-page/login.jsp/form-login-page

form-error-page/error.jsp/form-error-page

/form-login-config

/login-config

security-role

descriptionRole 1/description

role-namerole1/role-name

/security-role

/web-app

測(cè)試

打開tomcat目錄下的conf/tomcat-users.xml文件,內(nèi)容如下

?xml version='1.0' encoding='utf-8'?

tomcat-users

role rolename="tomcat"/

role rolename="role1"/

user username="tomcat" password="tomcat" roles="tomcat"/

user username="role1" password="tomcat" roles="role1"/

user username="both" password="tomcat" roles="tomcat,role1"/

/tomcat-users

啟動(dòng)tomcat,在瀏覽器中輸入地址,顯示的內(nèi)容不是/web/index.html,而是login.jsp的內(nèi)容,輸入both或者role1的用戶名和密碼,將會(huì)看到web/index.html的內(nèi)容,當(dāng)然,如果輸入錯(cuò)誤,則會(huì)提示錯(cuò)誤信息。驗(yàn)證通過(guò)后,我們可以看到如下內(nèi)容:

request.FORM_AUTH:FORM

request.getRemoteUser():both? //用戶名

sun公司也有提供了一個(gè)關(guān)于JAAS的實(shí)例,可供實(shí)際分析JAAS使用原理,本人在網(wǎng)上找了許久這方面的文章,希望對(duì)你有幫助。

1、首先下載實(shí)例代碼

2、SampleAcn.java 放在 sample 目錄中, SampleLoginModule.java 放在 sample/module 之下, 而 SamplePricipal 放在 sample/principal 之下。

3、將 config 和 policy 配置文件放到項(xiàng)目的根目錄中,切記,否則無(wú)法找到此文件。

4、將所有文件編譯后執(zhí)行以下命令

java -Djava.security.auth.login.config==sample_jaas.config sample.SampleAcn

如果使用Eclipse則在Run... SampleAcn.java 類時(shí)把-Djava.security.auth.login.config==sample_jaas.config 參數(shù)填寫入Arguments標(biāo)簽頁(yè)面的VM arguments框中。

5、此時(shí)在控制臺(tái)顯示要求用戶輸入user name:和password:,分別輸入testUser和testPassword即可驗(yàn)證通過(guò)。

至于Jaas原理,有時(shí)間可以研究一下源代碼即可。

怎么使用Java來(lái)監(jiān)控內(nèi)存?求具體實(shí)例代碼。

其實(shí)首先你可以先使用監(jiān)控內(nèi)存工具,來(lái)監(jiān)控下,如果內(nèi)存消耗不是很大,其實(shí)就不用那么麻煩了。如果實(shí)在要加個(gè)內(nèi)存監(jiān)控程序,可以使用Runtime中的MaxMemory、TotalMemory、FreeMemory來(lái)實(shí)現(xiàn)。注意這些都是JVM的內(nèi)存,請(qǐng)不要和系統(tǒng)的內(nèi)存混淆。另外如果要實(shí)時(shí)監(jiān)控,必須還得弄個(gè)線程類。大致思路是這樣,至于內(nèi)存溢出,你可以設(shè)定一個(gè)內(nèi)存閾值,比如說(shuō)15%的剩余內(nèi)存設(shè)置,就報(bào)內(nèi)存即將溢出的錯(cuò)誤。

分享名稱:java實(shí)例代碼下載,java實(shí)例大全
本文鏈接:http://muchs.cn/article12/hcjegc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、App開發(fā)、定制網(wǎng)站、動(dòng)態(tài)網(wǎng)站ChatGPT、標(biāo)簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)