??xml version="1.0" encoding="utf-8" standalone="yes"?> Tomcat的各个组件在$CATALINA_HOME/conf/server.xml文g中配|,其基本结构如下: web.xml文g基本格式Q?大小写敏感、元素次序敏? 每个Java虚拟机实例都有一个方法区以及一个堆Q它们是p虚拟机实例中所有线E共享的?/span> Java栈由许多栈Q?/span>stack frmeQ或者说帧(frameQ组成,一个栈帧包含一个方法调用。当U程调用一?/span>JavaҎӞ虚拟机压入一个新的栈帧到该线E的java栈中Q当该方法返回时Q这个栈帧被?/span>Java栈中弹出q抛弃?/span> Java虚拟机没有寄存器Q其指o集?/span>Java栈来存储中间数据?/span> 数据cd Java虚拟机是通过某些数据cd来执行计的Q数据类型及其运都是由java虚拟范严格定义的。数据类型可以分ZU:基本cd和引用类型。基本类型的变量持有原始|而引用类型的变量持有引用倹{术?#8220;引用?#8221;指的是对某个对象的引用,而不是该对象本nQ与此相对,原始值则是真正的原始数据?/span>Java语言中的所有基本类型同样也都是java虚拟Z的基本类型,但是boolean有点特别Q虽然虚拟机也把boolean看做基本cdQ但是指令集?/span>boolean只有很有限的支持。当~译器把java源码~译成字节码Ӟ它会?/span>int?/span>byte来表C?/span>boolean。设?/span>boolean值的操作会?/span>intQ?/span>boolean数组是当?/span>byte数组来访问的。但是在“?#8221;ZQ它也可以被表示Z域?br />
cd 范围 byte 8bitQ带W号Q二q制补码Q?/span>[-2?,2?-1] short 16bitQ带W号Q二q制补码Q?/span>[-2?5,2?5-1] int 32bitQ带W号Q二q制补码Q?/span>[-2?1,2?1-1] long 64bitQ带W号Q二q制补码Q?/span>[-2?3,2?3-1] char 16bitQ不带符PUnicode字符Q?/span>[0,2?6-1] float 32bitQ?/span>IEEE 754标准单精度QҎ double 64bitQ?/span>IEEE 754标准双进度QҎ returnAddress 同一Ҏ中某操作码的地址 reference 堆中Ҏ对象的引用,或者是null Java虚拟ZQ最基本的数据单元就是字Q?/span>wordQ,它的大小是由每个虚拟机实现的设计者来军_的。字长必够大Q至是一个字单元p以持?/span>byte?/span>short?/span>int?/span>char?/span>float?/span>returnAddress?/span>referencecd的|而两个字单元p以持?/span>long或?/span>doublecd的倹{因此,虚拟机实现的设计者至得选择32位作为字ѝ?/span> Ҏ?/span> ׃所有线E都׃nҎ区,因此它们Ҏ法区数据的访问必被设计为线E安全的?/span> cd信息 Ҏ个装载的cdQ虚拟机都会在方法区中存储以下类型信息: l q个cd的全限定?/span> l q个cd的直接超cȝ全限定名 l q个cd是类cdq是接口cd l q个cd的访问修饰符 l M直接接口的全限定名的有序列?/span> 除这些基本信息外Q还需要如下信息: l 该类型的帔R?/span> l 字段信息 l Ҏ信息 l 除了帔R以外的所有类变量 l 一个到c?/span>ClassLoader的引?/span> 一个到Classcȝ引用
* 21:24 2006-10-12
* @author blackbat
* @title jsp中文ql极解决Ҏ
*/
q可能出现的地方:1 jsp面?nbsp;
2 jsp面之间怺传参的参?br />
3 与数据库中数据的存取
基本归纳Z上几U?br />
?nbsp;L解决Ҏ
1 出现在jsp面中,是由于没有设|jsp面的中文字W编码?br />
2 出现在jsp面之间怺传参Q是׃参数没有讄正确的字W编码?br />
3 以上2个问题解决了Q那么存到数据库中,自然׃存在q。除非你对存入到数据库里的数据再ơ进行编码?/span>
1的解x?nbsp;
<% @ page contentType = " text/html;charset=gb2312 " %>
加上q句解决jsp面中的中文q昄,tomcat~译完后向客L输出的html文g不是?br />
用中文编码,所以会Dq产生?br />
2的解x?br />
2.1 <% request.setCharacterEncoding( " gb2312 " ); %>
加上q句解决jsp面中的中文参数传递ؕ码?br />
因ؓ览器默认用的~码?#8220;UTF-8”发送请求参数?br />
我们把它改ؓ"gb2312"ok了?br />
2.2 String(request.getParameter("name").getBytes("ISO8859_1"),"GB2312");
q句的意思是Q把传来的参数全部编码{换成gb2312Q这样做的缺Ҏ每次传来一个参?br />
都要q样写,很麻烦?br />
同样可通过讄server.xml配置文g来实现?br />
< Connector
port ="8080" maxHttpHeaderSize ="8192"
maxThreads ="150" minSpareThreads ="25" maxSpareThreads ="75"
enableLookups ="false" redirectPort ="8443" acceptCount ="100"
connectionTimeout ="20000" disableUploadTimeout ="true" URIEncoding ="gb2312" />
但是q样应用到整个webapp中去了?br />
另: <% @page pageEncoding = " gb2312 " %>
此句是ؓ了让jsp~译器能正确地解码含有中文字W的jsp面?br />
其它Ҏq可以修改web.xml文gQ配|一个过滤器。其原理都一P只是换种方式而已?br />
有的书上专门写了一个函数来解决qQ实际上Ҏ一下就知道那种解决Ҏ的好与坏?br />
回过头来一看,解决q也不q如此?br />
okQ实际就加上q?句搞定问题?br />
<% @page pageEncoding = " gb2312 " %>
<% @ page contentType = " text/html;charset=gb2312 " %>
<% request.setCharacterEncoding( " gb2312 " ); %>
请大家有什么想法,以及有什么不对的地方请各位说明,写在留言上,大家一赯论?/span>
转蝲自:http://www.aygfsteel.com/blackbat/archive/2008/04/27/74865.html
]]>
Categories of Java HotSpot VM Options
Standard options recognized by the Java HotSpot VM are described on the Java Application Launcher reference pages for Windows, Solaris and Linux. This document deals exclusively with non-standard options recognized by the Java HotSpot VM:
* Options that begin with -X are non-standard (not guaranteed to be supported on all VM implementations), and are subject to change without notice in subsequent releases of the JDK.
* Options that are specified with -XX are not stable and are not recommended for casual use. These options are subject to change without notice.
Default values are listed for Java SE 6 for Solaris Sparc with -server. Some options may vary per architecture/OS/JVM version. Platforms with a differing default value are listed in the description.
* Boolean options are turned on with -XX:+<option> and turned off with -XX:-<option>.
* Numeric options are set with -XX:<option>=<number>. Numbers can include 'm' or 'M' for megabytes, 'k' or 'K' for kilobytes, and 'g' or 'G' for gigabytes (for example, 32k is the same as 32768).
* String options are set with -XX:<option>=<string>, are usually used to specify a file, a path, or a list of commands
Flags marked as manageable are dynamically writeable through the JDK management interface (com.sun.management.HotSpotDiagnosticMXBean API) and also through JConsole. In Monitoring and Managing Java SE 6 Platform Applications, Figure 3 shows an example. The manageable flags can also be set through jinfo -flag.
The options below are loosely grouped into three categories.
* Behavioral options change the basic behavior of the VM.
* Performance tuning options are knobs which can be used to tune VM performance.
* Debugging options generally enable tracing, printing, or output of VM information.
Behavioral Options
-XX:-AllowUserSignalHandlers Do not complain if the application installs signal handlers. (Relevant to Solaris and Linux only.)
-XX:AltStackSize=16384 Alternate signal stack size (in Kbytes). (Relevant to Solaris only, removed from 5.0.)
-XX:-DisableExplicitGC Disable calls to System.gc(), JVM still performs garbage collection when necessary.
-XX:+FailOverToOldVerifier Fail over to old verifier when the new type checker fails. (Introduced in 6.)
-XX:+HandlePromotionFailure The youngest generation collection does not require a guarantee of full promotion of all live objects. (Introduced in 1.4.2 update 11) [5.0 and earlier: false.]
-XX:+MaxFDLimit Bump the number of file descriptors to max. (Relevant to Solaris only.)
-XX:PreBlockSpin=10 Spin count variable for use with -XX:+UseSpinning. Controls the maximum spin iterations allowed before entering operating system thread synchronization code. (Introduced in 1.4.2.)
-XX:-RelaxAccessControlCheck Relax the access control checks in the verifier. (Introduced in 6.)
-XX:+ScavengeBeforeFullGC Do young generation GC prior to a full GC. (Introduced in 1.4.1.)
-XX:+UseAltSigs Use alternate signals instead of SIGUSR1 and SIGUSR2 for VM internal signals. (Introduced in 1.3.1 update 9, 1.4.1. Relevant to Solaris only.)
-XX:+UseBoundThreads Bind user level threads to kernel threads. (Relevant to Solaris only.)
-XX:-UseConcMarkSweepGC Use concurrent mark-sweep collection for the old generation. (Introduced in 1.4.1)
-XX:+UseGCOverheadLimit Use a policy that limits the proportion of the VM's time that is spent in GC before an OutOfMemory error is thrown. (Introduced in 6.)
-XX:+UseLWPSynchronization Use LWP-based instead of thread based synchronization. (Introduced in 1.4.0. Relevant to Solaris only.)
-XX:-UseParallelGC Use parallel garbage collection for scavenges. (Introduced in 1.4.1)
-XX:-UseParallelOldGC Use parallel garbage collection for the full collections. Enabling this option automatically sets -XX:+UseParallelGC. (Introduced in 5.0 update 6.)
-XX:-UseSerialGC Use serial garbage collection. (Introduced in 5.0.)
-XX:-UseSpinning Enable naive spinning on Java monitor before entering operating system thread synchronizaton code. (Relevant to 1.4.2 and 5.0 only.) [1.4.2, multi-processor Windows platforms: true]
-XX:+UseTLAB Use thread-local object allocation (Introduced in 1.4.0, known as UseTLE prior to that.) [1.4.2 and earlier, x86 or with -client: false]
-XX:+UseSplitVerifier Use the new type checker with StackMapTable attributes. (Introduced in 5.0.)[5.0: false]
-XX:+UseThreadPriorities Use native thread priorities.
-XX:+UseVMInterruptibleIO Thread interrupt before or with EINTR for I/O operations results in OS_INTRPT. (Introduced in 6. Relevant to Solaris only.)
Performance Options
-XX:+AggressiveOpts Turn on point performance compiler optimizations that are expected to be default in upcoming releases. (Introduced in 5.0 update 6.)
-XX:CompileThreshold=10000 Number of method invocations/branches before compiling [-client: 1,500]
-XX:LargePageSizeInBytes=4m Sets the large page size used for the Java heap. (Introduced in 1.4.0 update 1.) [amd64: 2m.]
-XX:MaxHeapFreeRatio=70 Maximum percentage of heap free after GC to avoid shrinking.
-XX:MaxNewSize=size Maximum size of new generation (in bytes). Since 1.4, MaxNewSize is computed as a function of NewRatio. [1.3.1 Sparc: 32m; 1.3.1 x86: 2.5m.]
-XX:MaxPermSize=64m Size of the Permanent Generation. [5.0 and newer: 64 bit VMs are scaled 30% larger; 1.4 amd64: 96m; 1.3.1 -client: 32m.]
-XX:MinHeapFreeRatio=40 Minimum percentage of heap free after GC to avoid expansion.
-XX:NewRatio=2 Ratio of new/old generation sizes. [Sparc -client: 8; x86 -server: 8; x86 -client: 12.]-client: 4 (1.3) 8 (1.3.1+), x86: 12]
-XX:NewSize=2.125m Default size of new generation (in bytes) [5.0 and newer: 64 bit VMs are scaled 30% larger; x86: 1m; x86, 5.0 and older: 640k]
-XX:ReservedCodeCacheSize=32m Reserved code cache size (in bytes) - maximum code cache size. [Solaris 64-bit, amd64, and -server x86: 48m; in 1.5.0_06 and earlier, Solaris 64-bit and and64: 1024m.]
-XX:SurvivorRatio=8 Ratio of eden/survivor space size [Solaris amd64: 6; Sparc in 1.3.1: 25; other Solaris platforms in 5.0 and earlier: 32]
-XX:TargetSurvivorRatio=50 Desired percentage of survivor space used after scavenge.
-XX:ThreadStackSize=512 Thread Stack Size (in Kbytes). (0 means use default stack size) [Sparc: 512; Solaris x86: 320 (was 256 prior in 5.0 and earlier); Sparc 64 bit: 1024; Linux amd64: 1024 (was 0 in 5.0 and earlier); all others 0.]
-XX:+UseBiasedLocking Enable biased locking. For more details, see this tuning example. (Introduced in 5.0 update 6.) [5.0: false]
-XX:+UseFastAccessorMethods Use optimized versions of Get<Primitive>Field.
-XX:-UseISM Use Intimate Shared Memory. [Not accepted for non-Solaris platforms.] For details, see Intimate Shared Memory.
-XX:+UseLargePages Use large page memory. (Introduced in 5.0 update 5.) For details, see Java Support for Large Memory Pages.
-XX:+UseMPSS Use Multiple Page Size Support w/4mb pages for the heap. Do not use with ISM as this replaces the need for ISM. (Introduced in 1.4.0 update 1, Relevant to Solaris 9 and newer.) [1.4.1 and earlier: false]
Debugging Options
-XX:-CITime Prints time spent in JIT Compiler. (Introduced in 1.4.0.)
-XX:ErrorFile=./hs_err_pid<pid>.log If an error occurs, save the error data to this file. (Introduced in 6.)
-XX:-ExtendedDTraceProbes Enable performance-impacting dtrace probes. (Introduced in 6. Relevant to Solaris only.)
-XX:HeapDumpPath=./java_pid<pid>.hprof Path to directory or filename for heap dump. Manageable. (Introduced in 1.4.2 update 12, 5.0 update 7.)
-XX:-HeapDumpOnOutOfMemoryError Dump heap to file when java.lang.OutOfMemoryError is thrown. Manageable. (Introduced in 1.4.2 update 12, 5.0 update 7.)
-XX:OnError="<cmd args>;<cmd args>" Run user-defined commands on fatal error. (Introduced in 1.4.2 update 9.)
-XX:OnOutOfMemoryError="<cmd args>;
<cmd args>" Run user-defined commands when an OutOfMemoryError is first thrown. (Introduced in 1.4.2 update 12, 6)
-XX:-PrintClassHistogram Print a histogram of class instances on Ctrl-Break. Manageable. (Introduced in 1.4.2.) The jmap -histo command provides equivalent functionality.
-XX:-PrintConcurrentLocks Print java.util.concurrent locks in Ctrl-Break thread dump. Manageable. (Introduced in 6.) The jstack -l command provides equivalent functionality.
-XX:-PrintCommandLineFlags Print flags that appeared on the command line. (Introduced in 5.0.)
-XX:-PrintCompilation Print message when a method is compiled.
-XX:-PrintGC Print messages at garbage collection. Manageable.
-XX:-PrintGCDetails Print more details at garbage collection. Manageable. (Introduced in 1.4.0.)
-XX:-PrintGCTimeStamps Print timestamps at garbage collection. Manageable (Introduced in 1.4.0.)
-XX:-PrintTenuringDistribution Print tenuring age information.
-XX:-TraceClassLoading Trace loading of classes.
-XX:-TraceClassLoadingPreorder Trace all classes loaded in order referenced (not loaded). (Introduced in 1.4.2.)
-XX:-TraceClassResolution Trace constant pool resolutions. (Introduced in 1.4.2.)
-XX:-TraceClassUnloading Trace unloading of classes.
-XX:-TraceLoaderConstraints Trace recording of loader constraints. (Introduced in 6.)
]]>
有如下两个对象:文章和关键字。它们之间的关系Q很明显Q是一对多的关p,一个文章可以有很多的关键字?br />
假设有文章atricleA、articleBQarticleA有关键字keyword1、keyword2QarticleB有关键字keyword3、keyword4?br />
我们现在x询含有关键字keyword1或者keyword3的所有文章列表,正确的结果应该是articleA和articleB两条记录。然而,如果使用hibernate不当Q有可能你得到的是articleA、articleA、articleB、articleB四条记录Q其中两条是重复的?br />
q是怎么发生的呢Q?br />
如果我们q样使用hibernate来实现这个查询:
queryString.append("from ArticleData where keyword=? or keyword=?");
String[] param = new String[]{"keyword1","keyword3"};
Query query = session.createQuery(queryString );
query.list();
看看hibernatel我们生成的sql语句Q?br />
from articletable article_table_,keywordtable keyword_table1_ ,keywordtable keyword_table2_
where article_table_.id=keyword_table1_.articleid and article_table_.id=keyword_table2_.articleid
and (keyword_table1_.name='keyword1' or keyword_table2_.name='keyword3')
articleA keyword1 keyword2
aritcleB keyword3 keyword3
articleB keyword3 keyword4
正是我们之前所说得到的错误l果?br />
仔细分析q个sqlQ其实问题就出在hibernate生成sql的时候,对同一个表keywordtable查询了两ơ(在from中出Cơ)Q因此就有了l合的可能性,可以惌Q如果再多几个需要查询的关键字,同一个记录重复的ơ数会更多?br />
其实Q要正确的破解这个问题,我们可以自己写sql语句Q用hibernate同样支持的原生sql查询Q不使用hibernate的hql查询?br />
hibernate在给我们带来很多便利性的同时Q也l我们多多少带来了一些麻烦,而这些问题的定位成本可能也会很高。要使用好工Pp知道工具的优~点Q尤其是~点要有_的风险控制?br />
革命未成功Q同志仍需努力Q?br />
]]><Server>
<Service>
<Connector />
<Engine>
<Host>
<Context />
</Host>
</Engine>
</Service>
<Server>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Mivorsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app 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"
version="2.4">
<icon>
<small-icon>/images/app_small.gif</small-icon>
<large-icon>/images/app_large.gif</large-icon>
</icon>
<display-name>Application name</display-name>
<description>Description</description>
<distribute />
<context-param>
<param-name>contextParameter</param-name>
<param-value>test</param-value>
<description>It is a test parameter.</description>
</context-param>
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>EUC JP</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>listeners.SessionListener</listener-class>
</listener>
<servlet>
<servlet-name>snoop</servlet-name>
<servlet-class>SnoopServlet</servlet-class>
<init-param>
<param-name>foo</param-name>
<param-value>bar</param-value>
</init-param>
<run-as>
<description>Security role for anonymous access</description>
<role-name>tomcat</role-name>
</run-as>
<load-on-startup>1</load-on-statup>
</servlet>
<servlet>
<servlet-name>JspServlet</servlet-name>
<jsp-file>/test.jsp</jsp-file>
<init-param>
<param-name>firstName</param-name>
<param-value>tomcat</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>snoop</servlet-name>
<url-pattern>/snoop</servlet-name>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
<mime-mapping>
<extension>htm</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
<error-page>
<exception-type>packagename.classname</exception-type>
<location>exception.jsp</location>
</error-page>
<taglib>
<taglib-url>http://jakarta.apache.org/tomcat/debug-taglib</taglib-uri>
<taglib-location>/WEB-INF/jsp/debug-taglib.tld</taglib-location>
</taglib>
<resource-env-ref>
<resource-env-ref-name>jms/StockQueue</resource-env-ref-name>
</resource-env-ref>
<resource-ref>
<res-ref-name>mail/Session</res-ref-name>
<res-type>javax.mail.Sesssion</res-type>
<res-auth>Container</res-auth>
<resource-ref>
<security-constraint>
<display-name>Example Security Constraint</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/jsp/security/proctected/*</url-pattern>
<http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>tomcat</role-name>
<role-name>role1</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>Example Form-Based Authentication Area</realm-name>
<form-login-config>
<form-login-page>/jsp/security/protected/login.jsp</form-login-page>
<form-error-page>/jsp/security/protected/error.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>tomcat</role-name>
</security-role>
<env-entry>
<env-entry-name>minExemptions</env-entry-name>
<env-entry-value>1</env-entry-value>
<env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>
<ejb-ref>
<description>Example EJB Reference</description>
<ejb-ref-name>ejb/Account</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.mycompany.mypackage.AccountHome</home>
<remote>com.mycompany.mypackage.AccountRemote</remote>
</ejb-ref>
<ejb-local-ref>
<description>Example Local EJB Reference</description>
<ejb-ref-name>ejb/ProcessOrder</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.mycompany.mypackage.ProcessOrderHome</local-home>
<local>com.mycompany.mypackage.ProcessOrder</local>
</ejb-local-ref>
</web-app>
servlet 2.4中新增标{:
<locale-encoding-mapping-list>
<locale-encoding-mapping>
<locale>ja</locale>
<encoding>Shift_JIS</encoding>
</locale-encoding-mapping>
<locale-encoding-mapping>
<locale>zh_TW</locale>
<encoding>Big5</encoding>
</locale-encoding-mapping>
</locale-encoding-mapping-list>
<filter-mapping>
<filter-name>Logging Filter</filter-name>
<url-pattern>/products/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<jsp-config>
<taglib>
<taglib-uri>Taglib</taglib-uri>
<taglib-location>/WEB-INF/tlds/mytaglib.tld</taglib-location>
</taglib>
<jsp-property-group>
<description>Special property group for jsp configuration.</description>
<display-name>JspConfiguration</display-name>
<url-pattern>/jsp/*</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>UTF-8</page-encoding>
<scripting-invalid>true</scripting-invalid>
<include--prelude>/include/prelude.jsp</include-prelude>
<include-coda>/include/coda.jsp</include-coda>
</jsp-property-group>
</jsp-config>
]]>
图一 Java虚拟机的内部体系l构
当虚拟机装蝲一?/span>class文gӞ它会从这?/span>class文g包含的二q制数据中解析类型信息,然后把这些类型信息放到方法区中;
当程序运行时Q虚拟机会把所有该E序在运行时创徏的对象都攑ֈ堆中Q?/span>
当每一个新U程被创建时Q它都将得到它自qPC寄存器(E序计数器)以及一?/span>Java栈,如果U程正在执行的是一?/span>javaҎQ非本地ҎQ,那么PC寄存器的值将L指示下一条将被执行的指oQ而它?/span>Java栈则L存储该线E中javaҎ调用的状?/span>?span style="font-family: 宋体">包括它的局部变量,被调用时传进来的参数Q它的返回|以及q算的中间结果等{。而本地方法调用的状态,则是以某U依赖与具体实现的方式存储在本地Ҏ栈中Q也可能是在寄存器或者其他某些与特定实现相关的内存中?/span>
]]>
Java通过提供一?#8221;安全沙箱“来保证从|络或者其他不信Q的地方下载ƈq行的程序不会破坏本地数据,Z保沙箱是可靠的Qjava安全模型对体pȝ构的各方面都q行了考虑。组成java沙箱的基本组件如下:
Java的沙安全模型,最重要的优点之一是q些lg中的c装载器和安全管理器是可以由用户定制的?br />
1、类装蝲器体pȝ?/strong>
java沙箱中,c装载器体系l构是第一道防U,c装载器体系l构在三个方面对Java的沙pv作用Q?br />
?Q如果某个恶意的cd以成功欺骗Java虚拟机,使Java虚拟机相信它是一个来自Java API的可信Qc,那么Q这个恶意的cd可以H破沙箱的阻隔了Q让我们看看java如何Lq种情况的发生?br />
Java的类装蝲器结构是一个以启动c装载器为根的委zNQ子 c装载器在装载一个类旉先会h其双亲类装蝲器来装蝲Q如果双亲装载器能够装蝲成功Q则直接使用该类型,只有所有双亲类装蝲器都装蝲p|的时候,才会Ҏ自定义的Ҏ去装载该cdQ这中工作方式被UC”双亲委派模式“?br />
在这U模式下Q如果一个自定义的网l类装蝲器试图从|络上下载一个和Java API中某个类型同名的cdQ如java.lang.IntegerӞ它将不能成功Q因为通过层层委派Q这个类型会被启动类装蝲器装载,而网l类装蝲器将直接使用正确的java.lang.IntegerQ而没有机会从|络上下载ƈ装蝲q个恶意的java.lang.Integer?br />
?Q如果自定义的网l类装蝲器不像例1一样去替换一个被信Q的类Q而是在被信Q的包中插入一个全新的cdQ比如,一个java.lang.Virus的时候,会发生什么?
通过层层委派Q网l类装蝲器最l会正确装蝲q个名ؓjava.lang.Virus的类Q暗CZq个cLJava API的一部分Q因此,它可以访问java.lang包中被信ȝ的特D访问权限(protectedQ,然而,q个情况不会发生Q因为java虚拟机只把彼此访问的Ҏ权限授予由同一个类装蝲器装载到同一个包中的cdQ即只有同一?#8221;q行时包“的类之间才有Ҏ讉K权限Q而java.lang.Virus和java.lang中其他被信Q的类分别有网l类装蝲器和启动c装载器装蝲Q它们不属于同一个运行时包?br />
4、安全管理器和Java API
java安全模型的前三个部分共同辑ֈ了一个目的:保持java虚拟机的实例和它正在q行的应用程序的内部完整性,使得它们不被下蝲的恶意或有漏z的代码늊。相反,java安全模型的第四个l成部分---安全理?--则用于保护虚拟机外部资源不被虚拟机内q行的恶意或有漏z的代码늊。这个安全管理器是一个单独的对象Q在q行的java虚拟ZQ它在访问控?--对于外部资源的访问控?--中v中枢作用?br />
安全理器定义了沙箱的外部边界,q且它是可以定制的?
安全理器中需要了解如下一些概念和c:
q部分内容太多,只能带过了?br />
Java安全模型的不?/strong>
Java安全模型不能解军_下问题:
以上两中cd的攻击被UC拒绝服务dQDOSQ?br />
另一个没有放入安全模型的领域是关于将权限映射到系l用P代码以这个用L名义来运行。这中访问控制在unixpȝ中较为常见,它基于用户IDҎ件的讉Kq行控制?/p>
二、Java虚拟?/p>
Java虚拟机是Java的面向网l的核心Q它支持Java面向|络体系l构三大支柱的所有方面:q_无关性,安全性和|络Ud性。Java虚拟机的主要d是装载class文gq且执行其中的字节码。classloader负责装蝲class文gQ执行引擎负责执行字节码?br />
执行引擎
׃Java虚拟范只定义了每个虚拟机都必d现的Ҏ,没有规定具体的实现方法,因此不同的Java虚拟机,执行引擎可能实现的非怸同,一般来说有如下几种实现ҎQ?/p>
Classloader
一个java应用E序可以有两U类装蝲器:启动c装载器(bootstrap)和用户定义的c装载器Q启动类装蝲器是唯一的,它属于Java虚拟机实现的一部分?br />
每一个类装蝲器都有它自己的命名空_一个类只能”看到“由同一个类装蝲器装载的其他c,不能跨命名空间访问?br />
用过允许实例化用戯定义的类装蝲器(该类装蝲器知道如何从|络下蝲class文gQ,Javac装载器的体pȝ构提供了对网l移动性的支持Q通过允许使用不同的用户定义的c装载器装蝲不同来源的class文gQJavac装载器的体pȝ构提供了对完全性的支持?/p>