⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 第一个acegi 程式 - 表单网页.htm

📁 acegi+spring最新的分析
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0070)http://caterpillar.onlyfun.net/GossipCN/AcegiGossip/FirstAcegPage.html -->
<HTML><HEAD><TITLE>第一个Acegi 程式 - 表单网页</TITLE><LINK 
href="第一个Acegi 程式 - 表单网页.files/stdlayout.css" type=text/css rel=stylesheet><LINK 
href="第一个Acegi 程式 - 表单网页.files/print.css" type=text/css rel=stylesheet>
<META http-equiv=content-type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.3199" name=GENERATOR></HEAD>
<BODY>
<H3><A 
href="http://caterpillar.onlyfun.net/GossipCN/index.html">http://caterpillar.onlyfun.net/GossipCN/index.html</A></H3>
<H1><A 
href="http://caterpillar.onlyfun.net/GossipCN/AcegiGossip/AcegiGossip.html">Acegi 
Gossip:&nbsp;第一个Acegi 程式 - 表单网页</A></H1>完成了 <A 
href="http://caterpillar.onlyfun.net/GossipCN/AcegiGossip/FirstAcegConfig.html">第一个Acegi 
程式 - 设定文件</A> 中的文件设定,接下来完成必要的表单网页,首先是/acegilogin.jsp:<BR>
<UL>
  <LI>acegilogin.jsp </LI></UL><PRE>&lt;%@page contentType="text/html"%&gt;<BR>&lt;%@page pageEncoding="UTF-8"%&gt;<BR>&lt;html&gt;<BR>&lt;head&gt;<BR>&lt;title&gt;Acegi 范例网页 - 登入&lt;/title&gt;<BR>&lt;/head&gt;<BR>&lt;body&gt;<BR>&lt;h2&gt;登入范例应用程式!&lt;/h2&gt;<BR>&lt;br /&gt;<BR>&lt;form action="<SPAN style="FONT-WEIGHT: bold">j_acegi_security_check</SPAN>" method="POST"&gt;<BR>&lt;table&gt;<BR>	&lt;tr&gt;<BR>		&lt;td&gt;名称:&lt;/td&gt;<BR>		&lt;td&gt;&lt;input type='text' name='<SPAN style="FONT-WEIGHT: bold">j_username</SPAN>' value=''&gt;&lt;/td&gt;<BR>	&lt;/tr&gt;<BR>	&lt;tr&gt;<BR>		&lt;td&gt;密码:&lt;/td&gt;<BR>		&lt;td&gt;&lt;input type='password' name='<SPAN style="FONT-WEIGHT: bold">j_password</SPAN>'&gt;&lt;/td&gt;<BR>	&lt;/tr&gt;<BR>	&lt;tr&gt;<BR>		&lt;td&gt;&lt;input name="reset" type="reset"&gt;&lt;/td&gt;<BR>		&lt;td&gt;&lt;input name="submit" type="submit"&gt;&lt;/td&gt;<BR>	&lt;/tr&gt;<BR>&lt;/table&gt;<BR>&lt;/form&gt;<BR>&lt;/body&gt;<BR>&lt;/html&gt;</PRE><BR>主要注意到粗体字的部份,j_acegi_security_check为 
<A 
href="http://caterpillar.onlyfun.net/GossipCN/AcegiGossip/FirstAcegConfig.html">第一个Acegi 
程式 - 设定文件</A> 
中authenticationProcessingFilter的filterProcessesUrl属性所设定的名称,而验证时发送的使用者名称与密码,要以j_username与j_password请求参数送出。<BR><BR>如果想要在登入失败时显示错误讯息,可以检查param.login_error是否为空,例如结合JSTL的话:<BR>
<DIV style="MARGIN-LEFT: 40px"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&lt;c:if 
test="${not empty param.login_error}"&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; 
&lt;font color="red"&gt;使用者名称或密码错误,请重新登入!&lt;BR&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp;&nbsp;&nbsp; 
&lt;/font&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&lt;/c:if&gt;</SPAN><BR></DIV><BR>您也许想显示最后一次登入失败的使用者名称,这个讯息是储存在session之中,可以使用AuthenticationProcessingFilter.ACEGI_SECURITY_LAST_USERNAME_KEY作为KEY来取得这个值,例如:<BR>
<DIV style="MARGIN-LEFT: 40px"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&lt;%@ 
page</SPAN><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"> 
import="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter"%&gt;<BR><BR>...<BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"></SPAN></DIV><BR>
<DIV style="MARGIN-LEFT: 40px"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&lt;input 
type='text' name='j_username'</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp; 
&nbsp; &lt;c:if test="${not empty param.login_error}"&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp; 
&nbsp;&nbsp;&nbsp; &nbsp; value='&lt;%= 
session.getAttribute(AuthenticationProcessingFilter.ACEGI_SECURITY_LAST_USERNAME_KEY) 
%&gt;'</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&nbsp; 
&nbsp; &lt;/c:if&gt;</SPAN><BR 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace"><SPAN 
style="FONT-WEIGHT: bold; FONT-FAMILY: Courier New,Courier,monospace">&gt;</SPAN><BR></DIV><BR>登入成功的话,可以显示/protected/loginsuccess.jsp<BR>
<UL>
  <LI>loginsuccess.jsp </LI></UL><PRE>&lt;%@page contentType="text/html"%&gt;<BR>&lt;%@page pageEncoding="UTF-8"%&gt;<BR>&lt;%@ page import="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter"%&gt;<BR><BR><BR>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"<BR>   "http://www.w3.org/TR/html4/loose.dtd"&gt;<BR><BR>&lt;html&gt;<BR>    &lt;head&gt;<BR>        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;<BR>        &lt;title&gt;登入成功&lt;/title&gt;<BR>    &lt;/head&gt;<BR>    &lt;body&gt;<BR>        <BR>    &lt;h1&gt;欢迎 &lt;%= session.getAttribute(AuthenticationProcessingFilter.ACEGI_SECURITY_LAST_USERNAME_KEY) %&gt;<BR>    &lt;/h1&gt;<BR>        <BR>    &lt;/body&gt;<BR>&lt;/html&gt;</PRE><BR>登入成功,但不是正确的角色时,会发生授权失败的例外,这时会送往/protected/accessDenied.jsp:<BR>
<UL>
  <LI>accessDenied.jsp </LI></UL><PRE>&lt;%@page contentType="text/html"%&gt;<BR>&lt;%@page pageEncoding="UTF-8"%&gt;<BR><BR>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"<BR>   "http://www.w3.org/TR/html4/loose.dtd"&gt;<BR><BR>&lt;html&gt;<BR>    &lt;head&gt;<BR>        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;<BR>        &lt;title&gt;授权失败&lt;/title&gt;<BR>    &lt;/head&gt;<BR>    &lt;body&gt;<BR><BR>    &lt;h1&gt;授权失败&lt;/h1&gt;<BR>    <BR>    &lt;/body&gt;<BR>&lt;/html&gt;</PRE><BR>接着,设置一个简单的首页,当使用者存取首页时,直接转页至acegilogin.jsp:<BR>
<UL>
  <LI>index.jsp </LI></UL><PRE>  &lt;%@ page language="java" pageEncoding="UTF-8"%&gt;  <BR>  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;  <BR>  &lt;html&gt;  <BR>  &lt;head&gt;  <BR>  &lt;META HTTP-EQUIV="Refresh" CONTENT="0;URL=acegilogin.jsp"&gt;  <BR>  &lt;/head&gt;  <BR>  &lt;body&gt;  <BR>        &lt;p&gt;载入中...&lt;/p&gt;  <BR>  &lt;/body&gt;  <BR>  &lt;/html&gt;  </PRE><BR>现在您可以启动您的应用程式了,尝试直接存取acegilogin.jsp并登入,关闭浏览器并清除快取,再尝试直接存取/protected/下的资源,看看结果如何。<BR><BR></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -