??xml version="1.0" encoding="utf-8" standalone="yes"?>中文.日本.精品,欧美色另类天堂2015,日韩av片子http://www.aygfsteel.com/mashiguang/archive/2009/12/07/304958.htmlmashiguangmashiguangMon, 07 Dec 2009 01:50:00 GMThttp://www.aygfsteel.com/mashiguang/archive/2009/12/07/304958.htmlhttp://www.aygfsteel.com/mashiguang/comments/304958.htmlhttp://www.aygfsteel.com/mashiguang/archive/2009/12/07/304958.html#Feedback4http://www.aygfsteel.com/mashiguang/comments/commentRss/304958.htmlhttp://www.aygfsteel.com/mashiguang/services/trackbacks/304958.html使用cas?/span>sso helloword

因ؓ工作需要接触到ssoQ据知目前多?/span>sso使用耉?/span>cas实现Q且发现使用cas真的是很单就可以做出一个单点登录系l来Q?/span>casq提供丰富的扩展功能Q对于扩展功能日后再l细研究Q这里只使用cas做一?/span>hello world来记录本人的学习q程Q如有幸被高人看刎ͼq望指出弊病Q不吝赐教?/span>

在?/span>cas之前最好对数字证书有所了解Q不了解也没有关p,跟着我的步骤也一样可以跑的通?/span>

准备工作

需要的文gQ?/span>

ü         Jdk6

ü         Tomcat

ü         cas-server-3.3.2

ü         cas-client-3.1.9

证书

下面?/span>keytool命o的一些常用方法,先在q里认识一下它们,一会儿会用的到?/span>

使用keytool命o生成密钥?/span>

keytool -genkey -alias tomcat -keyalg RSA -dname "CN=pcma, OU=vanceinfo, O=vanceinfo, L=haidian, S=beijing, C=CN" -keystore c:"keystore5.jks

CNQ主机名

OUQ组l单?/span>

OQ组l?/span>

LQ地?/span>

SQ城?/span>

CQ国?br />
如果需要指定密钥有效期Q添?validity 365卛_Q单位是天,如:
keytool -genkey -alias tomcat -keyalg RSA -dname "xxxxx" -keystore xxxxx -validity 365

导出证书

keytool -export -file c:/server5.crt -alias tomcat -keystore c:"keystore5.jks

证书导入到客户?/span>jdk

keytool -import -keystore "D:"Java"jdk1.6.0_14"jre"lib"security"cacerts" -file c:/server5.crt -alias tomcat

从密钥库中删除指定别名的证书

keytool -delete -noprompt -alias tomcat -keystore E:"apache-tomcat-6.0.20_2"conf"keystore2.jks

查看密钥库中的证?/span>

keytool -list -v -keystore c:"keystore5.jks

配置tomcat

使用keytool命o生成密钥库?/span>

配置%tomcat_home%/conf/server.xml?/span>tomcat支持SSL协议Qƈ指定密钥库?/span>

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"

               maxThreads="150" scheme="https" secure="true"

               clientAuth="false" sslProtocol="TLS" keystorePass="mashiguang"

                        keystoreFile="${catalina.home}/conf/keystore5.jks"/>

部vcas server

解压~?/span>cas-server-3.3.2-release.zip文gQ在modules目录里找?/span>cas-server-webapp-3.3.2.war文gQ这是一个做好了?/span>cas服务端,我们做的sso helloword可以直接使用Q只需?/span>cas-server-webapp-3.3.2.war改了个简单点的名字,?/span>cas.warQ然后部|到tomcat卛_?/span>

览器访?/span>https://pcma:8443/casQ如果打开昄的是cas默认的登录页面,则表C服务端已部|完毕?/span>

客户端?/span>cas client

新徏两个web工程Q用于模拟单点登录系l中的客LQƈ?/span>cas-client-3.1.9"modules里的jar包放?/span>web工程lib目录下,是主要的?/span>cas-client-core-3.1.9.jar文gQ把spring2.5也放?/span>lib目录下?/span>

Web.xml文g

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4"

       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">

       <context-param> 

        <param-name>contextConfigLocation</param-name> 

        <param-value> 

            /WEB-INF/config/casContext.xml  

        </param-value> 

    </context-param> 

    <listener> 

        <listener-class> 

            org.springframework.web.context.ContextLoaderListener  

        </listener-class> 

    </listener> 

    <!-- 负责用户认证 --> 

    <filter> 

        <filter-name>CAS Authentication Filter</filter-name> 

        <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class> 

        <!-- CAS login 服务地址--> 

        <init-param> 

            <param-name>casServerLoginUrl</param-name> 

            <param-value>https://pcma:8443/cas/login</param-value> 

        </init-param> 

        <init-param> 

            <param-name>renew</param-name> 

            <param-value>false</param-value> 

        </init-param> 

        <init-param> 

            <param-name>gateway</param-name> 

            <param-value>false</param-value> 

        </init-param> 

        <!-- 客户端应用服务地址--> 

        <init-param> 

            <param-name>serverName</param-name> 

            <param-value>http://pcma:8081</param-value> 

        </init-param> 

    </filter> 

    <!--负责Ticket校验--> 

    <filter> 

        <filter-name>CAS Validation Filter</filter-name> 

        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 

        <init-param> 

            <param-name>targetBeanName</param-name> 

            <param-value>cas.validationfilter</param-value> 

        </init-param> 

    </filter> 

    <filter-mapping> 

        <filter-name>CAS Authentication Filter</filter-name> 

        <url-pattern>/*</url-pattern> 

    </filter-mapping> 

    <filter-mapping> 

        <filter-name>CAS Validation Filter</filter-name> 

        <url-pattern>/*</url-pattern> 

    </filter-mapping> 

</web-app>

casContext.xml文g

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"

              "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<bean id="cas.validationfilter" class="org.jasig.cas.client.validation.Cas10TicketValidationFilter"> 

        <property name="ticketValidator"> 

            <ref bean="cas10TicketValidator"/> 

        </property> 

        <property name="useSession"> 

            <value>true</value> 

        </property> 

        <!-- 客户端应用服务地址--> 

        <property name="serverName"> 

            <value>http://pcma:8081</value> 

        </property> 

        <property name="redirectAfterValidation"> 

            <value>true</value> 

        </property> 

    </bean> 

    <bean id="cas10TicketValidator" class="org.jasig.cas.client.validation.Cas10TicketValidator"> 

    <!-- q里参数?/span>cas服务器的地址--> 

        <constructor-arg index="0" value="https://pcma:8443/cas" /> 

    </bean> 

</beans> 

新徏index.jsp文g

 <body>

   hello sso<br>

   <a >sso2</a>q个地址是另外一台机器上?/span>sso客户?/span>

 </body>

上面?/span>web.xml?/span>casContext.xml?/span>index.jsp是两个客L中的一个,另一个要Ҏ实际情况修改?/span>

最后不要忘记客L?/span>jdk要?/span>keytool命o导入证书文g?/span>

启动tomcatQ测试器讉Khttp://pcma:8081/ssoQ出?/span>casd面Q输入相同的用户名和密码卛_dQ登录成功后面自动跌{?/span>http://pcma:8081/ssoQ这时点击页面上?/span>sso2链接Q就可以自动dq蟩转到sso2应用?/span>

如果输入用户名密码后提示下面的异常,是因为部|客L?/span>jdk没有导入证书文g的原因?/span>

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target


源码

http://www.aygfsteel.com/Files/mashiguang/sso.zip



mashiguang 2009-12-07 09:50 发表评论
]]>
jndi调用?各种应用服务器InitialContext的写?/title><link>http://www.aygfsteel.com/mashiguang/archive/2008/07/14/214758.html</link><dc:creator>mashiguang</dc:creator><author>mashiguang</author><pubDate>Mon, 14 Jul 2008 08:35:00 GMT</pubDate><guid>http://www.aygfsteel.com/mashiguang/archive/2008/07/14/214758.html</guid><wfw:comment>http://www.aygfsteel.com/mashiguang/comments/214758.html</wfw:comment><comments>http://www.aygfsteel.com/mashiguang/archive/2008/07/14/214758.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mashiguang/comments/commentRss/214758.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mashiguang/services/trackbacks/214758.html</trackback:ping><description><![CDATA[<p><br /> 调用ejb?如果客户端和ejb不在同一个jvm,p讄InitialContext,不同的应用服务器InitialContext写法也不?<br /> Context.INITIAL_CONTEXT_FACTORY:指定到目录服务的q接工厂<br /> Context.PROVIDER_URL:目录服务提供者URL</p> <p>//jboss:<br /> Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"<br /> Context.URL_PKG_PREFIXES, "org.jboss.naming"<br /> Context.PROVIDER_URL, "localhost:1099"</p> <p>//weblogic:<br /> Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"<br /> Context.PROVIDER_URL, "t3://localhost:7001"</p> <p>//apusic(金蝶):<br /> Context.INITIAL_CONTEXT_FACTORY, "com.apusic.jndi.InitialContextFactory"<br /> Context.PROVIDER_URL, "rmi://localhost:6888"</p> <p>//WebSphere:<br /> Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"<br /> Context.PROVIDER_URL, "iiop://localhost:900"</p> <p><br /> //J2EE  SDK(J2EE  RI):<br /> Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory"<br /> Context.PROVIDER_URL, "iiop://127.0.0.1:1050"</p> <p>//SilverStream:<br /> Context.INITIAL_CONTEXT_FACTORY, "com.sssw.rt.jndi.AgInitCtxFactory"<br /> Context.PROVIDER_URL, "sssw://localhost:80"</p> <p>//OC4J:<br /> Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory"<br /> Context.PROVIDER_URL, "ormi://127.0.0.1/"</p> <p>//WAS5:<br /> Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"<br /> Context.PROVIDER_URL, "iiop://localhost:2809"</p> <p> </p> <p>常用JNDI服务提供者连接工?<br /> Filesystem:  Com.sun.jndi.fscontext.FSContextFactory或者com.sun.jndi.fscontext.RefFSContextFactory<br /> LDAPv3:    Com.sun.jndi.ldap.LdapCtxFactory<br /> NDS:     com.novell.naming.service.nds.NdsInitialContextFactory<br /> NIS:     com.sun.jndi.nis.NISCtxFactory<br /> RMI registry: com.sun.jndi.rmi.registry.RegistryContextFactory<br /> IBM LDAP服务提供?   com.ibm.jndi.LDAPCtxFactory<br /> BEA 名字服务提供?   weblogic.jndi.WLInitialContextFactory<br /> JBOSS名字服务提供?  org.jnp.interfaces.NamingContextFactory</p> <img src ="http://www.aygfsteel.com/mashiguang/aggbug/214758.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mashiguang/" target="_blank">mashiguang</a> 2008-07-14 16:35 <a href="http://www.aygfsteel.com/mashiguang/archive/2008/07/14/214758.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java自动打包的差?/title><link>http://www.aygfsteel.com/mashiguang/archive/2007/12/13/167549.html</link><dc:creator>mashiguang</dc:creator><author>mashiguang</author><pubDate>Thu, 13 Dec 2007 09:03:00 GMT</pubDate><guid>http://www.aygfsteel.com/mashiguang/archive/2007/12/13/167549.html</guid><wfw:comment>http://www.aygfsteel.com/mashiguang/comments/167549.html</wfw:comment><comments>http://www.aygfsteel.com/mashiguang/archive/2007/12/13/167549.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mashiguang/comments/commentRss/167549.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mashiguang/services/trackbacks/167549.html</trackback:ping><description><![CDATA[自JDK1.0开始就存在包装器类,但是在JDK5.0之前,必须手工地插入打包和拆包的代?<br /> JDK5.0中就有了自动打包功能,但在5.0中自动打包时存在一些差?刚才看《java核心技术第7版》时才发?<br /> <br /> <span style="color: #ff0000">代码1:<br /> </span> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">Integer a</span><span style="color: #000000">=</span><span style="color: #000000">1000</span><span style="color: #000000">;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />Integer b</span><span style="color: #000000">=</span><span style="color: #000000">1000</span><span style="color: #000000">;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />System.out.println(a</span><span style="color: #000000">==</span><span style="color: #000000">b);</span><span style="color: #008000">//</span><span style="color: #008000">false</span></div> <span style="color: #ff0000">代码2:</span><br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">Integer a</span><span style="color: #000000">=</span><span style="color: #000000">100</span><span style="color: #000000">;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />Integer b</span><span style="color: #000000">=</span><span style="color: #000000">100</span><span style="color: #000000">;<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />System.out.println(a</span><span style="color: #000000">==</span><span style="color: #000000">b);</span><span style="color: #008000">//</span><span style="color: #008000">true</span></div> <span style="color: #ff0000">代码3:</span><br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" /><span style="color: #000000">Integer a</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Integer(</span><span style="color: #000000">100</span><span style="color: #000000">);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />Integer b</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000"> Integer(</span><span style="color: #000000">100</span><span style="color: #000000">);<br /> <img alt="" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" />System.out.println(a</span><span style="color: #000000">==</span><span style="color: #000000">b);</span><span style="color: #008000">//</span><span style="color: #008000">false</span></div> <br /> <p>W一D代码不成立,而第二段代码成立的原因是:自动打包<br /> <span style="color: #ff0000">自动打包规范要求boolean,byte,char≤127,介于-128→127之间的short和int被包装到固定的对象中.</span><br /> 打包和拆包是~译器认可的Q而不是虚拟机Q编译器在生成类的字节码Ӟ插入必要的方法调用,虚拟机只是执行这些字节码?/p> <p>W三D代码不用多说肯定不成立.</p> <p> </p> <img src ="http://www.aygfsteel.com/mashiguang/aggbug/167549.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mashiguang/" target="_blank">mashiguang</a> 2007-12-13 17:03 <a href="http://www.aygfsteel.com/mashiguang/archive/2007/12/13/167549.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ant打ear包的详细步骤http://www.aygfsteel.com/mashiguang/archive/2007/11/24/162758.htmlmashiguangmashiguangFri, 23 Nov 2007 16:44:00 GMThttp://www.aygfsteel.com/mashiguang/archive/2007/11/24/162758.htmlhttp://www.aygfsteel.com/mashiguang/comments/162758.htmlhttp://www.aygfsteel.com/mashiguang/archive/2007/11/24/162758.html#Feedback1http://www.aygfsteel.com/mashiguang/comments/commentRss/162758.htmlhttp://www.aygfsteel.com/mashiguang/services/trackbacks/162758.html阅读全文

mashiguang 2007-11-24 00:44 发表评论
]]>
apache commons-emailhttp://www.aygfsteel.com/mashiguang/archive/2007/11/01/157533.htmlmashiguangmashiguangThu, 01 Nov 2007 08:51:00 GMThttp://www.aygfsteel.com/mashiguang/archive/2007/11/01/157533.htmlhttp://www.aygfsteel.com/mashiguang/comments/157533.htmlhttp://www.aygfsteel.com/mashiguang/archive/2007/11/01/157533.html#Feedback3http://www.aygfsteel.com/mashiguang/comments/commentRss/157533.htmlhttp://www.aygfsteel.com/mashiguang/services/trackbacks/157533.html使用commons mail旉要的jar?
1,commons-email-1.1.jar
2,mail.jar
3,activation.jar
(在web应用里只需要commons-email?

发送简单的文字邮g:

SimpleEmail email = new SimpleEmail();

email.setHostName(
"smtp.sina.com");
email.setAuthentication(
"username""password");//在邮件服务商处注册的用户名和密码
email.addTo("mailTo@163.com");
email.setFrom(
"username@sina.com""alias");

email.setCharset(
"UTF-8");//gbk或gb2312,只要支持中文p
email.setSubject("title");
email.setMsg(
"content");
email.send();

发送带附g的邮?
// Create the attachment
EmailAttachment attachment = new EmailAttachment();
attachment.setPath(
"mypictures/john.jpg");
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription(
"Picture of John");
attachment.setName(
"John");

// Create the email message
MultiPartEmail email = new MultiPartEmail();
email.setHostName(
"mail.myserver.com");
email.setAuthentication(
"username""password");
email.addTo(
"jdoe@somewhere.org""John Doe");
email.setFrom(
"me@apache.org""Me");
email.setCharset(
"UTF-8");
email.setSubject(
"The picture");
email.setMsg(
"Here is the picture you wanted");

// add the attachment
email.attach(attachment);

// send the email
email.send();

创徏多个EmailAttachment对象,q调用MultiPartEmail.attach();可以发送多个附?

发送HTML格式的邮?

发送html格式的邮件和单邮件的区别在创徏HtmlEmail对象
q用email.setHtmlMsg(String)或email.setMsg(String)把含有html标签的字W串赋给email对象.
HtmlEmail对象q有一个setTextMsg(String)Ҏ,q个Ҏ参数里的html标签会被当做普通字W处?不会被解析成html元素.
更详l内容可以看apache commons-email的用h?/a>.



mashiguang 2007-11-01 16:51 发表评论
]]>
<?gt;,防止h/后退引v的重复提交问题的Java Token代码Q非Strutshttp://www.aygfsteel.com/mashiguang/archive/2007/08/21/138324.htmlmashiguangmashiguangTue, 21 Aug 2007 03:45:00 GMThttp://www.aygfsteel.com/mashiguang/archive/2007/08/21/138324.htmlhttp://www.aygfsteel.com/mashiguang/comments/138324.htmlhttp://www.aygfsteel.com/mashiguang/archive/2007/08/21/138324.html#Feedback6http://www.aygfsteel.com/mashiguang/comments/commentRss/138324.htmlhttp://www.aygfsteel.com/mashiguang/services/trackbacks/138324.html贴子转自http://hi.baidu.com/bobylouQ{之前q没有验证文章里的方法是不是有效Q估计原作者把它放到blog之前应该做过试了吧?br>

Struts本n有一套完善的防止重复提交表单?strong>Token(令牌)机制Q但W者目前的目自写的framework没有用到StrutsQ故也得自写防止用户因ؓ后退或者刷新来重复提交表单内容的Token机制。不难,Ҏ实现?/p>

实现原理Q一致性。jsp生成表单Ӟ在表单中插入一个隐?lt;input>字段Q该字段是保存在页面端的token字符Ԍ同时把该字符串存入session中。等到用h交表单时Q会一q提交该隐藏的token字符丌Ӏ在服务器端Q查看下是否在session中含有与该token字符串相{的字符丌Ӏ如果有Q那么表明是W一ơ提交该表单Q然后删除存放于session端的token字符Ԍ再做正常业务逻辑程Q如果没有,那么表示该表单被重复提交Q做非正常流E处理,可以警告提示也可以什么也不做?/p>

看代码?/p>

首先?strong>Tokenȝ。类很简单,而且主要Ҏ都给doc注释?/p>

/*
* blog: 
http://hi.baidu.com/bobylou
* $Revision: 1.1 $
* $Date: 2007/07/18 10:02:55 $
* $Author: bobrow$
*/


package com.paizuo.framework.util;

import java.util.ArrayList;

import javax.servlet.http.HttpSession;

public class Token {

    
private static final String TOKEN_LIST_NAME = "tokenList";

    
public static final String TOKEN_STRING_NAME = "token";

    
private static ArrayList getTokenList(HttpSession session) {
       Object obj 
= session.getAttribute(TOKEN_LIST_NAME);
       
if (obj != null{
          
return (ArrayList) obj;
       }
 else {
          ArrayList tokenList 
= new ArrayList();
          session.setAttribute(TOKEN_LIST_NAME, tokenList);
          
return tokenList;
       }

    }


    
private static void saveTokenString(String tokenStr, HttpSession session) {
       ArrayList tokenList 
= getTokenList(session);
       tokenList.add(tokenStr);
       session.setAttribute(TOKEN_LIST_NAME, tokenList);
    }

   
    
private static String generateTokenString(){
       
return new Long(System.currentTimeMillis()).toString();
    }


    
/**
     * Generate a token string, and save the string in session, then return the token string.
     * 
     * 
@param HttpSession
     *            session
     * 
@return a token string used for enforcing a single request for a particular transaction.
     
*/

    
public static String getTokenString(HttpSession session) {
       String tokenStr 
= generateTokenString();
       saveTokenString(tokenStr, session);
       
return tokenStr;
    }


    
/**
     * check whether token string is valid. if session contains the token string, return true. 
     * otherwise, return false.
     * 
     * 
@param String
     *            tokenStr
     * 
@param HttpSession
     *            session
     * 
@return true: session contains tokenStr; false: session is null or tokenStr is id not in session
     
*/

    
public static boolean isTokenStringValid(String tokenStr, HttpSession session) {
       
boolean valid = false;
       
if(session != null){
          ArrayList tokenList 
= getTokenList(session);
          
if (tokenList.contains(tokenStr)) {
             valid 
= true;
             tokenList.remove(tokenStr);
          }

       }

       
return valid;
    }

}



怎么使用Q?/font>

在jsp面端?/strong>

首先import该类Q?/p>

<%@ page import="com.paizuo.framework.util.Token" %>

表单包含隐藏的token字符?

 

<form>

<input type="hidden" name="<%=Token.TOKEN_STRING_NAME %>" value="<%=Token.getTokenString(session) %>">

</form>

 

在Server端action中进行检验?/strong>

 

if(Token.isTokenStringValid(request.getParameter(Token.TOKEN_STRING_NAME), request.getSession())){
//q行正常业务程
}

else{
//q行防重复提交处理流E?/span>
}

完毕?/p>

mashiguang 2007-08-21 11:45 发表评论
]]>
servlet使用技?l臃肿的web.xml瘦n.http://www.aygfsteel.com/mashiguang/archive/2007/07/06/128653.htmlmashiguangmashiguangFri, 06 Jul 2007 11:17:00 GMThttp://www.aygfsteel.com/mashiguang/archive/2007/07/06/128653.htmlhttp://www.aygfsteel.com/mashiguang/comments/128653.htmlhttp://www.aygfsteel.com/mashiguang/archive/2007/07/06/128653.html#Feedback5http://www.aygfsteel.com/mashiguang/comments/commentRss/128653.htmlhttp://www.aygfsteel.com/mashiguang/services/trackbacks/128653.htmlweb.xml里也密密麻麻的排满了<servlet><servlet-mapping>q些食之无味弃之崩溃的东?有一U方法可以改善这U境?
      在web.xml里添加如下的配置:
    <servlet>
        
<servlet-name>InvokerServlet</servlet-name>
        
<servlet-class>
          org.apache.catalina.servlets.InvokerServlet
        
</servlet-class>
        
<init-param>
            
<param-name>debug</param-name>
            
<param-value>0</param-value>
        
</init-param>
        
<load-on-startup>-1</load-on-startup>
    
</servlet>
    
    
<servlet-mapping>
        
<servlet-name>InvokerServlet</servlet-name>
        
<url-pattern>/servlet/*</url-pattern>
    
</servlet-mapping>
      ok,现在web.xml里保留这一个servlet配置可以满x有的servlet调用?比如调用UserManagerServiceq个servlet,在页面表单里q样?
<form name="f" method="post" action="/servlet/com.mashiguang.servlet.UserManagerService">
      
<input/>
      
<submit/>
</form>
      注意表单action "/servlet/"后面是这个servlet class的全?

mashiguang 2007-07-06 19:17 发表评论
]]>
վ֩ģ壺 | | | | ͤ| | İ| | | | ƽ| Ž| | | | ˫| | | ͭ| Դ| | ƽ| | ͨɽ| | | | ٺ| ƽ| Ȫ| ʼ| ʯ| ǰ| | | ˮ| | żҽ| | | Ϫ|