搜档网
当前位置:搜档网 › Fine-structure Constant, Anomalous Magnetic Moment, Relativity Factor and the Golden Ratio

Fine-structure Constant, Anomalous Magnetic Moment, Relativity Factor and the Golden Ratio

Fine-structure Constant, Anomalous Magnetic Moment, Relativity Factor and the Golden Ratio
Fine-structure Constant, Anomalous Magnetic Moment, Relativity Factor and the Golden Ratio

Fine-structure Constant, Anomalous Magnetic Moment, Relativity Factor and the Golden Ratio that Divides the Bohr Radius

R. Heyrovska (1) and S. Narayan (2)

((1) J. Heyrovsky Institute of Physical Chemistry, Prague, Czech Republic and (2) Villa

Julie College, Stevenson, MD, USA )

Sommerfeld introduced the fine-structure constant (α) into physics, while he was taking into account the relativistic effects in the theory of the hydrogen atom. Ever since, it has puzzled many scientists like Eddington, Dirac, Feynman and others. Here the mysterious fine-structure constant, α (= λC,H/λdB = 1/137.036 = 2.627/360) is interpreted based on the finding that it is close to φ2/360 (= 2.618/360 = 1/137.508), where λC,H, the Compton wavelength for hydrogen is a distance equivalent to an arc length on the circumference λdB (= 2πa B) of a circle with the Bohr radius (a B) and φ is the Golden ratio, which was recently shown to divide the Bohr radius (a B) into two Golden sections at the point of electrical neutrality. From the data for the electron (e-) and proton (p+) g-factors, it is found that (360/φ2) - α-1 = 2/φ3 = (g p - g e)/(g p + g e), where 360/φ2 = λdB/(λC,H - λC,H,i), λC,H,i = φ2πrμ,H and rμ,H is the sum of the intrinsic radii of e- and p+ evaluated from the g-factors and that

α ? φ2/360 = 0.009/360 = λC,H,i/λdB = (1- γ)/γ, the factor for the advance of perihilion in Sommerfeld’s theory of the hydrogen atom, where γ is the relativity factor.

This world year of physics, WYP 2005, is also concerned with the mystery of the fine-structure constant (α) which puzzled Feynman [1]: “ ... is it related to pi or perhaps to the base of natural logarithms? Nobody knows. It's one of the greatest damn mysteries of physics: a magic number that comes to us with no understanding by man. You might say the

"hand of God" wrote that number, ..." , see Gilson [2a]. α and its relation to the g-factors are recently rousing considerable interest [2 - 5]. The constancy (or not) of α defined as

2πe2/κhc, where e, κ, h and c are respectively, the charge, electric permittivity of free space, Planck’s constant and the speed of electromagnetic waves in vacuum, is being debated

mostly in terms of these parameters. The present relation between α and the magnetic

moment anomalies expressed as a long series of terms [6] is too complicated to comprehend. This work investigates α from a different point of view, on observing that it is close to φ2/360 (= 1/137.508), where φ is the Golden ratio [7], also called the Divine ratio (Feynman thought of π or e!), which was recently found [8,9] to play an important role in atomic physics.

φ is a mathematical constant which operates in a wide variety of geometrical workings in

the Universe ranging from mollusks in the sea to the spiral galaxies in the cosmos [7]. Geometrically, when the segments a and b of a line of length d are such that (a + b)/a = a/b,

the ratio a/b = (1 + 51/2)/2 = φ = 1.618033989... , and a (= d/φ) and b (= d/φ2) are called the Golden sections. Nature works through the remarkable and unique property of φ that the

power series, ..., 1/φ2, 1/φ, 1, φ, φ2, φ3, …, is at the same time also a Fibonacci series (0, 1, 1,

2, 3, 5, 8, etc.), where any Fibonacci number is related to its neighbors as follows: e.g., 3 =

1 +

2 = 5 – 2. Thus, φ = (1/φ) + 1 = φ2 – 1. Also, note that φ2/π = 0.833346 ~ (5/6).

In the case of a hydrogen atom, which consists of an electron (e-) and a proton (p+) (with magnetic moments μe and μp respectively) separated by the Bohr radius a B, it was shown recently [8] that the ground state energy (E H) is given by the difference,

E H = (1/2)(e2/κa B) = (1/2)(e2/κ)[(1/a B,p) - (1/a B,e)] = eI H = hνH(1a) 1/a B = (1/a B,p) - (1/a B,e); a B = a B,e + a B,p; (a B,e/a B,p)2 - (a B,e/a B,p) = 1 (1b-d)

where I H is the ionization potential of hydrogen, I e = -e/(κa B,e) and I p = e/(κa B,p) are the component potentials of (e-) and (p+) respectively, νH = c/λH is the frequency of light that ionizes hydrogen and λH is the corresponding wavelength. From Eqs. (1b,c), one obtains the Golden quadratic equation Eq. (1d) whose positive root is a B,e/a B,p = φ. This shows that a B is divided at the point of electrical neutrality P el into the two Golden sections, a B,e = a B/φ and

a B,p = a B/φ2 = a B,e - a B/φ3.

The above interpretation in terms of the Golden ratio was extended to other atoms and further, it was shown [8]that for any two atoms of the same kind, the covalent bond distance

is the sum of its Golden sections, the larger one being the anionic and the smaller one, the cationic radius of the atom. This enabled assignment of ionic radii for atoms, and many

bond lengths were shown to be additive. E.g., the crystal ionic distances of alkali halides

could be quantitatively reproduced by adding the respective ionic radii.

Since the de Broglie wavelength, λdB (= 2πa B) is equal to the circumference of the circle

with the radius a B, it is also the sum of the circumferences of two Golden circles, λdB,e =

2πa B,e = (2πa B)/φ and λdB,p = 2πa B,p = (2πa B)/φ2 with the radii a B,e and a B,p. These are also

equal to the Golden arc lengths corresponding to the Golden angles, (2π/φ) and (2π/φ2)

radians or 3600/φ (= 222.492o) and 3600/φ2 (= 137.508o) respectively. Note: 2π radians (=

2πr/r)are divided into 360 degrees where both the radian and the degree are dimensionless.)

α (=2πe2/κhc = 1/137.036 = 2.627/360) is the ratio of wavelengths,

α = λC,H/λdB = λdB/(λH/2) (2)

where λC,H = λC,e + λC,p, the sum of the Compton wavelength shifts for the electron and proton, corresponds to an arc length, subtended by a central angle of 360/137.036 =

2.6270 (= φ2 + 0.009), of the circumference λdB of the circle. Since α = λC,H/λdB = r C,H/a B, it

is the ratio of r C,H (= λC,H/2π), the Compton radius, which is related to the magnetic

moments and a B, which is associated with the electrical charges of e- and p+. r C,H is given by,

μB + μN = (e/2μH,red)h bar = (ec/2)r C,H(3a)

h bar = h/2π = cm e r C,e = cm p r C,p = cμH,red r C,H(3b)

μB/r C,e = μN/r C,p = (μB + μN)/r C,H = ec/2 (3c)

where μB = (ec/2)r C,e = (e/2m e)h bar is the Bohr magneton and μN = (ec/2)r C,p = (e/2m p)h bar is

the nuclear magneton, r C,H = r C,e + r C,p, m e and m p are the rest masses of the electron and

proton, respectively, and μH,red = m e m p/(m e + m p) is the reduced mass of hydrogen. Eq. (3c)

shows that the magnetic pole strength is ec/2.

The g-factor (g e/2) for the electron is defined as the ratio μe/μB, and is given by,

μe = (g e/2)μB = (1 + a e)μB = μB + μe,intr = (ec/2)Rμ,e (4a)

g e/2 = Rμ,e/r C,e = (c/h bar)m e Rμ,e = Iμ,e/I (4b)

where μe,intr = a eμB = (ec/2)rμ,e can be considered as the intrinsic magnetic moment of the

electron, rμ,e is the intrinsic radius, a e = rμ,e/r C,e, is the electron magnetic moment anomaly

[6b] and Rμ,e = r C,e + rμ,e. Eq. (4b) shows that g e/2 is the ratio of the moments Iμ,e = m e Rμ,e

(due to the magnetic moment) and I = h bar/c.

Similarly, μN and μp are related by g p/2 as shown,

μp = (g p/2)μN = (1 + a p)μN = μN + μp,intr = (ec/2)Rμ,p (5a)

g p/2 = Rμ,p/r C,p = (c/h bar)m p Rμ,p = Iμ,p/I (5b)

where μp,intr = a pμN = (ec/2)rμ,p is the intrinsic magnetic moment of the proton, rμ,p is the

intrinsic radius, a p = rμ,p/r C,p is the proton magnetic moment anomaly and Rμ,p = r C,p + rμ,p.

Eq. (5b) shows that g p/2 is proportional to the moment, Iμ,p = m p Rμ,p.

On dividing a B into the sections aμ,e and aμ,p at a point, Pμ [8,9] such that the moments of

inertia (due to the magnetic moments), Iμ,e aμ,e = Iμ,p aμ,p, one obtains,

Iμ,e/Iμ,p = m e Rμ,e/m p Rμ,p = m eμe/m pμp = aμ,p/aμ,e = g e/g p = 0.3585 (6a) (aμ,e - aμ,p)/a B = (g p – g e)/(g e + g p) = 2/φ3 =2(a B,e - a B,p)/a B = 360/φ2 - α-1(6b)

In Eq. (6b), use of the data from [6c] for the g-factors gives (g p – g e)/(g e + g p) = 0.472 = 2/φ3

and therefore, g e/g p = (φ3 – 2)/(φ3 + 2); see also [9].

From Eqs. (2) and (4) - (6), one finds that 360/φ2 stands for the ratio,

360/φ2 = λdB/(λC,H - λC,H,i) (7)

where, λC,H,i = φ2πrμ,H and rμ,H = rμ,e +rμ,p. The distances, λC,H, (λC,H - λC,H,i) and λC,H,i

correspond to small arc lengths on the circle of circumference λdB, subtended by central

angles of 2.6270, 2.6180 (= φ2) and 0.0090 (= 2.627 - 2.618) respectively.

On noting that 0.0090 = 360(1 - γ)/γ = 0.009(6)0, the advance of the perihelion in Sommerfeld’s theory [10] of the hydrogen atom, where γ = (1- α2)1/2 = 0.99997(3) is the

relativity factor when the angular momentum p = h bar, one obtains the following relations,

λC,H,i/λdB = α ? φ2/360 = (1 - γ)/γ and γ = λdB/(λdB + λC,H,i) = 0.99997(5) (8a,b)

Thus the Golden ratio provides a quantitative link between the various known quantities in atomic physics.

Figure 1 shows the role of φ in the hydroegn atom and the caption gives all the details.

One of us (R. H.) is thankful to the Ministry of Industry and Trade of the Czech Republic (project No. 1H-PK/42) for the financial support.

References:

[1] S-I. Tomonaga, J. Schwinger and R. P. Feynman,

https://www.sodocs.net/doc/f47529941.html,/physics/laureates/1965/

[2] a) J. G. Gilson, https://www.sodocs.net/doc/f47529941.html,/~ugah174/and b)

https://www.sodocs.net/doc/f47529941.html,/wiki/Fine-structure_constant

[3] P. Tzanavaris et al., Phys. Rev. Lett. 95, 041301 (2005); and the literature cited therein.

[4] C. Seife, Science, 306, 793 (2004).

[5] a) P. Davies et al., Nature, 418, 602 (2002) and b) T. Davis,

https://www.sodocs.net/doc/f47529941.html,.au/sao/guest/davis/

[6] a) P. J. Mohr and B. N. Taylor, Phys. Today, 54, 29 (2001) and b)

https://www.sodocs.net/doc/f47529941.html,/cuu/constants/

[7] a) M. Livio, M. The Golden Ratio, the story of phi, the world’s most astonishing number. (Broadway Books, New York, 2002) and b) https://www.sodocs.net/doc/f47529941.html,

[8] R. Heyrovska, Mol. Phys., 103, 877 (2005) and the literature therein.

[9] R. Heyrovska and S. Narayan, 2nd IUPAP International Conference on Women in Physics, Rio de Janeiro, Brazil, May 2005, Poster. Abstract in:

https://www.sodocs.net/doc/f47529941.html,.br/eventos/wp/ii/sys/resumos/R0100-2.pdf

[10] A. E. Ruark and H. C. Urey, Atoms, molecules and quanta, Volume I, (Dover Publications, New York, 1964), p. 134.

Figure 1. The Golden ratio, point of electrical neutrality (P el) and magnetic center (Pμ) of the hydrogen atom.

AB = aΒ (= 5.29465x10-11m, from the data in [6c]), the Bohr radius, is the distance between the electron (e-) with magnetic moments μe at A and proton (p+) with magnetic moments μp at B, and O is the center of AB. The (auxiliary) right-angled triangle ABC is constructed for locating the point of electrical neutrality, P el, such that BC = BO = a B/2 = CD. This makes, AC = √5a B/2 and AD = a B/φ, where φ = 1.618034. P el is then marked on AB so that AP el = AD = a B/φ = a B,e and BP el = a B,p = a B/φ2.

EA = AP el = a B/φ = 0.618a B and BG = BP el = a B/φ2 = 0.382a B. F is the center of EG (=

2a B) and 2FO = 2OP el = FP el = (a B,e - a B,p) = a B/φ3 = 0.236a B, The circumference of the circle EHGJE with F as the center = 2πa B = λdB, the de Broglie wavelength. The Golden angles HFJ = 360/φ2 (= 137.5080) and 360/φ (= 222.4920). The Golden arcs HGJ = (2π/φ2)a B = λdB,p and HEJ = (2π/φ)a B = λdB,e. Note that a common tangent to these two circles from a point beyond G (not shown in Fig. 1), will be inclined to AB at an angle sin-1(a B,e - a B,p)/a B = sin-1(1/φ3).

Pμ, the magnetic center, is located such that (g e/g p) = aμ,p/aμ,e, 2P el Pμ = FP el = a B/φ3, APμ = aμ,e = a B/2 + (a B/φ3) = (φ3 + 2)/2φ3 =0.736a B, BPμ = (g e/g p)aμ,e = aμ,p = a B/2 – (a B/φ3) = (φ3 - 2)/2φ3 = 0.264a B and (aμ,e - aμ,p)/a B = 2/φ3 = 360/φ2 - α-1. Note: The chord HJ intersects AB at I close to Pμ and BI = 0.255a B.

The sum of the Compton wavelengths of (e-) and (p+), λC,H (= αλdB), (λC,H - λC,H,i) [= (φ2/360)λdB] and λC,H,i {= φ2πrμ,H = (α ? φ2/360)λdB = [(1 - γ)/γ]λdB, where rμ,H is the sum of the intrinsic radii of (e-) and (p+) and γ is the relativity factor,} correspond to arc lengths, on the circle EHGJE of circumference λdB, which subtend at the center F, the angles, 2.627o, 2.618o (= φ2) and 0.009o respectively.

实验六 利用Struts2实现自定义拦截器

1、自定义拦截器,实现对注册页面上的文字信息进行过滤拦截,不允许出现字符集合中{“佛法”,”集会”,”党派”}的文字信息。如出现,则返回到注册页面,重新填写。 2、定义拦截器,实现登录检查。由于在项目开发时,需要对大多数的页面进行登录检查。当没有登录就无法进行操作,并返回到登录页面。为减少代码量利用Struts2中自定义拦截器的功能,实现登录检查。(避免不登录直接访问某个Action) Web.xml struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter actionPackages com.mycompany.myapp.actions struts2 /* WDF_INTERCEPTOR_6 index.html index.htm index.jsp default.html default.htm default.jsp struts.xml

Struts2学习笔记

Struts2项目的构建与配置 1.配置struts.xml (1)配置struts.xml可以参考下载的struts-2.3.14.1-all.zip解压后的apps文件夹下的 参考项目的struts.xml文件。 (2)主要的配置如下: /hello.jsp value="true"表示是开发模式,当修改了配置时服务器会自动加载修改后的配置,不需要中期服务器,方便开发。 (3)namespace="/"与浏览器的访问地址有关,namespace的默认值为空。 (4)/hello.jsp action的name值与浏览器的访 问地址有关,当地址是“http://…/hello”时,浏览器就会返回result中的hello.jsp 的页面。 2.配置web.xml (1)配置web.xml也可以参考下载的struts-2.3.14.1-all.zip解压后的apps文件夹下的 参考项目的web.xml文件 (2)主要配置如下: struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 /* 3.配置Struts2的jar包 (1)复制下载的struts-2.3.14.1-all.zip解压后的apps文件夹下的参考项目的 WEB-INF\lib文件夹下的所有的jar包到我们自己项目的WEB-INF\lib文件夹下即可。 Struts.xml的配置 1.package的属性与配置 (1)package的使用说明:类似于Java程序里的package,主要用于区分同名的action。在真 正的项目开发中package通常来区分不同的模块。例如: (2)name属性:用于区分不同的package,此属性不能省略不写。 (3)extends属性:用于继承其他的package,继承了某个package就包含了某个package里 的所有配置,此属性可以省略不写,默认继承struts-default。 (4)namespace属性:表示浏览器访问的路径,此属性可以省略不写,默认为空,当此属性 为空时,该package里的action可以匹配浏览的任何请求的action。 (5)abstract属性:此属性的值为false表示此package非抽象的,若为true表示此package

Struts2+Spring3+Hibernate4+Maven整合

Struts2+Spring3+Hibernate4+Maven整合 目录 1.建立Maven工程 2.搭建Spring3 3.搭建Struts2并整合Spring3 4.搭建Hibernate4并整合Spring3 内容 1.建立Maven工程 第一步: 第二步:

第三步:

第四步: 注意:这里的JDK要选择默认的,这样别人在使用的时候,如何JDk不一致的话也不会出错,如下图所示:

第五步: Maven标准目录 src/main/java src/main/resources src/test/java src/test/resources 第六步: 发布项目:Maven install 清除编译过的项目:Maven clean

OK,Mean 工程创建成功! 2. 搭建 Spring3

(1)下载Spring3需要的jar包 1.spring-core 2.spring-context 3.spring-jdbc 4.spring-beans 5.spring-web 6.spring-expression 7.spring-orm 在pom.xml中编写Spring3需要的包,maven会自动下载这些包。 org.springframework spring-core 3.1.2.RELEASE org.springframework spring-context 3.1.2.RELEASE org.springframework spring-jdbc 3.1.2.RELEASE org.springframework spring-beans 3.1.2.RELEASE org.springframework spring-web 3.1.2.RELEASE org.springframework spring-expression 3.1.2.RELEASE org.springframework spring-orm 3.1.2.RELEASE

struts2拦截器配置详解

Struts2拦截器详细配置过程 1:所有拦截器的超级接口Interceptor,拦截器去实现这个接口; Interceptor它其中有三个方法 (init(),destroy(),interceptor()):Init()方法:在服务器起动的时候加载一次,并且只加载一次; Destroy()方法:当拦截器销毁时执行的方法; Interceptor()方法:其中里边有一个参数invocation public String intercept(ActionInvocation invocation)throws xception { System.out.println("interceptor!!"); String result=invocation.invoke(); return result; }Invocation.invoke()是如果只有一个拦截器执行完这个方法后,会返回给视图,如果有多 个拦截器,它顺序的执行完所有的拦截器,才返回给视图. 2:可以在系统初始化中给拦截器指定默认的参数(也包括了定义拦截器方式)如下:在拦截器类中把hello当做属性set/get方式注入到拦截器类中;

张钊钊 也可以在使用拦截器的时候给它设置参数: 就是在一个action的reslut下面配置上如下: 2、警告:No configuration found for the specified action: 'sum.action' in namespace: ''. Form action defaulting to 'action' attribute's literal value. 分析及解决方法: 由于jsp文件中标签它对应的源文件是

,sturts把action属性值当成了一个action name了,但这也不影响使用;但是对于使用了动态方法调用(struts.enable.DynamicMethodInvocation = true)就没有那么幸运了,提交时就会得到HTTP Status 404 - /context/sum错误。对于以上情况,可以把标签写成 3、ERROR:Cannot create JDBC driver of class '' for connect URL 'null' 分析及解决方法: 这是由于tomcat下的server.xml里的没有配置好或没有相应的配置,可按如下配置: 4、ERROR:Cannot load JDBC driver class 'com.microsoft.jdbc.sqlserver.SQLServerDriver' 分析及解决方法: 这是由于JDBC的驱动没有装,可将sqlserver需要的三个驱动包msbase.jar,mssqlserver.jar,msutil.jar拷贝到tomcat的安装目录下的 common\lib文件夹下面即可。 5、ERROR:Cannot create resource instance 分析及解决方法: 这是由于里type属性设置不正确,按不同的数据库相应的做出调整就好了。 6、ERROR:https://www.sodocs.net/doc/f47529941.html,NotFoundException: Name jdbc is not bound in this Context 分析及解决方法: 这个很明显,上下文中找不到所给的jdbc名称,仔细查看纠正一下就好了 7、严重: Exception starting filter struts2、Error filterStart、Context [/struts2] startup failed due to previous errors 分析及解决方法: (1)在struts.xml中action中的包路径出错 (2)在工程中导入一个commons-fileupload的包 8、java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 'info' 无效 分析及解决方法: 出现这情况由两种可能性: (1)配置的数据库中没有info表或者是表名写错了,这是就要将其更改为info表所在的数据库名或

Struts2考试题分析

题目1 以下不届丁 Struts2中result 的type 届性() ? A. action B. redirect 题目2 下歹0有关拦截器说法错误的是? 「A.struts 通过拦截器完成执行action 请求处理方法前一系歹U 操作。例如: 数据封装、文件上传、数据校验等 'B.在struts 中,直接访问jsp 页面,struts 将使用默认拦截器栈处理当前 请求。 厂C.在执行action 时,struts 将执行若干拦截器1、2、3,执行action 完成 后,将继续执行拦截器3、2、1 'D.默认情况,在一个action 没有配置拦截器的引用,说明当前action 将不 使用拦截器 题目3 以下哪些是Action 接口提供的返回值? W A A. success ,D B. none C. error 财 D.input 题目4 如果要实现struts2的数据检验功能 广A 普通的Action 类可以实现 C. redirectAction D. dispatcher

「B继承自Action接口的可以实现 面C继承自ActionSupport类可以实现 厂D继承自ActionValidate 类可以实现 题目5 struts2默认的处理结果类型是: ? A.dispatcher ' B.redirect 「C.chain D. forward 题目6 在值栈的上下文Context中,存在一些固定的key表示不同的对象,以下描述正确的是? A. request,表示request作用域的数据 'B.session,表示session 作用域的数据 阿 C.application ,表示application 作用域的数据 * D.parameters ,表示请求参数的所有数据 题目7 以下届丁struts2配置文件中的配置元素是:()多选) A. B. 厂 C. 厂 D.

struts2.3.20环境搭建详解

Create Struts 2 Web Application With Artifacts In WEB-INF lib and Use Ant To Build The Application Edit Page Browse Space Add Page Add News You can download this complete example, Basic_Struts2_Ant, from Google Code - https://www.sodocs.net/doc/f47529941.html,/p/struts2-examples/downloads/list. Click on the link for Basic_Struts2_Ant.zip and save the file to your computer. Unzip the file and you should have a folder named Basic_Struts2_Ant. In that folder is a README.txt file with instruction on how to build and run the application. Icon This tutorial assumes you already know how to create a Java web application, use Ant to build the web application archive (war) file, and deploy the war file to a Servlet container such as Tomcat or Jetty. To create a Struts 2 web application with the Struts 2 artifacts added to the the application's class path manually you will need to download the Struts 2 distribution from the Apache Struts website. On the Struts 2 download page, click on the link for the current General Availability release. In that release's section you'll find several links. To get started with a basic Struts 2 web application you need to only download the Essential Dependencies Only zip file, which is approximately 12mb. After downloading this zip file, unzip it. You should have a folder named the same as the current general availability release and in that folder will be a lib folder. The lib folder contains the Struts 2 jar files (e.g. struts2-core-X.X.X.X.jar, where X.X.X.X is the version) and other jar files Struts 2 requires (e.g. xwork-core.X.X.X.jar). As we create our basic Struts 2 web application we will copy from the Struts 2 distribution lib folder just the jar files our application requires. As we add features to our application in future tutorials we will copy other jar files. Step 1 - Create A Basic Java Web Application In your Java IDE create a web application project named Basic_Struts2_Ant. To follow along with this tutorial your web application should have the following folder structure: Remember Struts 2 requires Servlet API 2.4 or higher, JSP 2.0 or higher, and Java 5 or higher. The example project, Basic_Struts2_Ant, which you can download from Google

Struts2自定义拦截器实现防止重复提交

由于struts2标签的性能不好,项目组决定不使用,但是如果用struts2自带的拦截器防止重复提交又必须struts标签,所以只好自定拦器实现,具体步骤如下: 新建拦截器类: public class TokenAtionInterceptor extends AbstractInterceptor { public String intercept(ActionInvocation invocation) throws Exception { Map session = invocation.getInvocationContext().getSession(); HttpServletRequest request = ServletActionContext.getRequest(); String strGUID = RandomGUIDUtil.newGuid(); //生成令牌 String strRequestToken = (String)session.get("request_token"); //取出会话中的令牌 String strToken = request.getParameter("token"); //页面中的令牌 if(strRequestToken != null && !strRequestToken.equals(strToken)){ //重复提交,重置令牌 session.put("request_token", strGUID); request.setAttribute("token", strGUID); return"invalidToken"; } session.put("request_token", strGUID); request.setAttribute("token", strGUID); return invocation.invoke(); //否则正常运行 } } 建一个生成令牌的工具类: public class RandomGUIDUtil extends Object { /**日志管理类对象*/ private Logger logger= Logger.getLogger(this.getClass().getName()); public String valueBeforeMD5 = ""; public String valueAfterMD5 = ""; private static Random myRand; private static SecureRandom mySecureRand; private static String s_id; /* * 静态块初始化

Struts 2 异常处理的常用的解决方法

一、第一个异常处理 严重: Servlet.service() for servlet jsp threw exception The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location] at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60) at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44) at https://www.sodocs.net/doc/f47529941.html,ponentTagSupport.doStartTag(ComponentTagSupport.java:48) at https://www.sodocs.net/doc/f47529941.html,_005fstruts2_005flz.YpxxbQuery_jsp._jspx_meth_s_005fdebug_005f0(Ypxxb Query_jsp.java:108) at https://www.sodocs.net/doc/f47529941.html,_005fstruts2_005flz.YpxxbQuery_jsp._jspService(YpxxbQuery_jsp.java:83) 解决的办法:(4种解决方案) 1. web.xml 中添加一个filter struts2 *.jsp struts2 /action/* 2. struts2 /* 注意这里一定要是/* 3. 这通常是由于不经由Filter访问包含struts标签的jsp页面导致的。那么,只要通过配置,使得对jsp页面的访问请求由Filter过滤转发即可。 方法1:在strut.xml中配置一个通用Action,通过这个Action转发到jsp页面。这个时候,原先访问jsp的请求路径就要换成相应的Action路径了。写法如下。 /{1}.jsp 方法2:在web.xml中配置Filter的url-parttern。写法如下。其中struts2-dispatcher 是已定义的Filter。

Struts2结果类型、拦截器、类型转换器

结果类型 Action处理完用户请求后,将返回一个普通的字符串,整个普通字符串就是一个逻辑视图。Struts2通过配置一个逻辑视图和物理视图的映射关系,一旦系统返回某个逻辑视图系统就会把对应的物理视图呈现给用户。 Struts2 在struts.xml中使用来配置结果,根据元素的位置不同可以分为两类: 局部结果:将 作为子元素来配置。 全局结果:将作为元素的子元素配置。 配置 元素时通常需要指定两个属性: name:该属性指定所需要的逻辑视图名 type:该属性指定结果类型: 常用的结果类型 结构类型含义 dispatcher默认,类似于JSP中forword服务器端的 分发 redirect直接跳转其他URL的结果类型,类似 与JSP的重定向 redirect-action直接跳转其他Action的结果类型 plainText用于展示某个页面原代码的结构类型 拦截器 Struts2中提供了很多特性都是通过拦截器实现的,例如异常处理,文件上传,生命周期回调和验证。拦截器从概念上来讲和Servlet过滤器 或JDK的Proxy类是一样的。提供了一种对Action进行预处理和事后处理的功能。 自定义拦截器 要自定义拦截器需要实现

com.opensymphony.xwork2.interceptor.Interceptor接口: public class PermissionInterceptor implements Interceptor { private static final long serialVersionUID = -5178310397732210602L; public void destroy() { } public void init() { } public String intercept(ActionInvocation invocation) throws Exception { System.out.println("进入拦截器"); if(session里存在用户){ String result = invocation.invoke(); }else{ return “logon”; } //System.out.println("返回值:"+ result); //return result; } } /WEB-INF/page/hello.jsp 因为struts2中如文件上传,数据验证,封装请求参数到action等功能都是由系统默认的defaultStack中的拦截器实现的,所以我们定义的拦截器需要引用系统默认的defaultStack,这样应用才可以使用struts2框架提供的

struts2国际化配置

前提条件:strut2的必须架包已经引入,struts2的配置文件全部配置完成 1.首先创建一个struts.properties在src目录下,服务器启动时候会自动加载该文件,在这个文件中写入struts.custom.i18n.resources=globalMessages,服务器会自动选择前缀为globalMessages资源文件。(或者你在你的struts.xml文件中添加服务器加载struts.xml的时候会加载国际化资源文件); 2.在src目录下创建资源文件英文globalMessages_en.properties 中文globalMessages_zh.properties。globalMessages_en.properties 文件内容为home=home globalMessages_zh.properties文件内容为home=¥u9996¥u9875 3.在页面端获得资源文件信息。<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> My JSP 'test.jsp' starting page struts2的国际化分三种情况 1.前台页面的国际化, 2.Action类中的国际化, 3.配置文件的国际化。 首先指定全局的国际化资源文件: 在配置文件struts.xml中引入 (注意位置)