网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java实例代码下载,java实例大全

求一个JAVA∶猫狗案例代码

代码如下

网站制作、建网站找专业网络公司创新互联建站:定制网站、模板网站、仿站、微信小程序定制开发、软件开发、app软件开发等。做网站价格咨询创新互联建站:服务完善、10年建站、值得信赖!网站制作电话: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("猫会跳高");

}

}

class Gou extends Dongwu implements Suan{

public void suan() {

System.out.println("狗会算数");

}

}

如果有帮助到你,请点击采纳

谁能提供给我weblogic上跑jaas的实例

这有个 jaas tomcat的实例, 先看下吧:

准备文件和目录

创建文件login.jsp和error.jsp

login.jsp的内容

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

在根目录下创建目录web,在新建的目录下创建一个文件index.jsp,内容如下

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

设置配置文件

在web.xml中添加以下内容

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

测试

打开tomcat目录下的conf/tomcat-users.xml文件,内容如下

?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

启动tomcat,在浏览器中输入地址,显示的内容不是/web/index.html,而是login.jsp的内容,输入both或者role1的用户名和密码,将会看到web/index.html的内容,当然,如果输入错误,则会提示错误信息。验证通过后,我们可以看到如下内容:

request.FORM_AUTH:FORM

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

sun公司也有提供了一个关于JAAS的实例,可供实际分析JAAS使用原理,本人在网上找了许久这方面的文章,希望对你有帮助。

1、首先下载实例代码

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

3、将 config 和 policy 配置文件放到项目的根目录中,切记,否则无法找到此文件。

4、将所有文件编译后执行以下命令

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

如果使用Eclipse则在Run... SampleAcn.java 类时把-Djava.security.auth.login.config==sample_jaas.config 参数填写入Arguments标签页面的VM arguments框中。

5、此时在控制台显示要求用户输入user name:和password:,分别输入testUser和testPassword即可验证通过。

至于Jaas原理,有时间可以研究一下源代码即可。

怎么使用Java来监控内存?求具体实例代码。

其实首先你可以先使用监控内存工具,来监控下,如果内存消耗不是很大,其实就不用那么麻烦了。如果实在要加个内存监控程序,可以使用Runtime中的MaxMemory、TotalMemory、FreeMemory来实现。注意这些都是JVM的内存,请不要和系统的内存混淆。另外如果要实时监控,必须还得弄个线程类。大致思路是这样,至于内存溢出,你可以设定一个内存阈值,比如说15%的剩余内存设置,就报内存即将溢出的错误。


网页题目:java实例代码下载,java实例大全
转载来于:http://bjjierui.cn/article/hcjegc.html

其他资讯