赞
踩
web项目中,会经常对用户登陆身份进行登陆验证
在tomcat 里可以实现一些简单的登陆验证,我们也不需要去写验证的方法,只需要对tomcat 配置文件和项目中web.xml进行一些简单的修改
tomcat/conf/server.xml
- <Engine name="Catalina" defaultHost="192.168.1.194"> <!-- 写为本机实际IP地址,否则其它机器无法正常访问 -->
- <!-- 数据库配置 -->
- <Realm className="org.apache.catalina.realm.JDBCRealm"
- connectionName="itc" connectionPassword="itc"
- driverName="oracle.jdbc.OracleDriver"
- connectionURL="jdbc:oracle:thin:@192.168.1.104:1521:ORCL"
- userTable="itcsys_user" userNameCol="userCode" userCredCol="passWord"
- userRoleTable="itcsys_user_group" roleNameCol="groupcode"/>
-
- <Host name="192.168.1.194" appBase="webapps"
-
- unpackWARs="true" autoDeploy="true"
- xmlValidation="false" xmlNamespaceAware="false">
- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> <!-- 使用单点登陆 -->
项目中
web.xml
- <security-constraint>
- <web-resource-collection>
- <web-resource-name>admin page</web-resource-name>
- <url-pattern>/admin/*</url-pattern> <!-- 需要验证的资源,可配置多个 -->
- </web-resource-collection>
- <auth-constraint>
- <role-name>admin</role-name>
- </auth-constraint>
- </security-constraint>
- <login-config>
- <auth-method>FORM</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>
- <role-name>admin</role-name>
- </security-role>
<FORM name="logonForm" method="post" action="j_security_check">
<input name="j_username" type="text" />
<input name="j_password" type="password" />
<input type="submit" value="LOGIN"/>
</FORM>
固定写法:
帐号 j_username
密码 j_password
action j_security_check
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。