【发布时间】:2013-03-24 12:02:40
【问题描述】:
Tomcat j_security_check 的快速问题...
任何人都知道如何在 user_role 表中将 'user_name' 更改为 'id',我更愿意这样做 通过匹配 ID 而不是用户名来验证
服务器.xml
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost/test"
connectionName="root" connectionPassword="password"
userTable="user" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_role_link" roleNameCol="role_id" />
表格
user
id INT PK
user_name PK
user_pass
role
id INT PK
role_name
user_role
user_id FK user_id to user.id
role_id FK role_id to role.id
表格依旧:
<form method="post" action="j_security_check" name="loginForm">
<j:if test='${not empty param["failed"]}'>
Invalid sign-in credentials<br/>
</j:if>
<h:inputText id="j_username" autocomplete="off" />
<br/>
<h:inputSecret id="j_password" autocomplete="off"/>
<br/>
<h:commandButton type="reset" value="Clear"/>
<h:commandButton type="submit" value="Login"/>
</form>
我已经让 role_id 工作,但使用 user_id 我只是得到一个
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'user_name' in 'where clause'
异常
提前致谢
KPS
【问题讨论】:
-
用
userNameCol="id"替换userNameCol="user_name"? -
我想过,但只是得到相同的 403 访问被拒绝和异常,但使用 'id' 而不是 user_name。
标签: java tomcat j-security-check