无法传递参数apache shiro jsp servlet

Posted

技术标签:

【中文标题】无法传递参数apache shiro jsp servlet【英文标题】:Cannot pass parameters apache shiro jsp sevlet 【发布时间】:2019-10-18 18:04:26 【问题描述】:

表单提交后,参数没有传递给servlet。附上 html 提交页面。在 shiro.ini 文件中有 JDBC 领域。

 `<form name="loginForm" method="get" action="LoginCheckController">
        <table  bgcolor="0099CC" align="center">
            <input type="hidden" id="action"  name="page" value="home"/>

            <tr>
                <td colspan=2><center>
                        <font size=4><b>HTML Login Page</b></font>
                    </center></td>
            </tr>

            <tr>
                <td>Username:</td>
                <td><input name="username" id="username" type="text" size=25 ></td>
            </tr>

            <tr>
                <td>Password:</td>
                <td><input name="password" type="password" size=25 ></td>
            </tr>

            <tr>
                <td><input type="Reset"></td>
                <td><input type="submit" value="Login"></td>
            </tr>

        </table>
    </form>`

这是 shiro.ini 配置文件。有一个jdbc领域。它用于获取日志记录详细信息。初始日志文件是 login.jsp。所有参数都给出了 null 结果。

[main]                  
##creating the realm
  jdbcRealm=org.apache.shiro.realm.jdbc.JdbcRealm
  jdbcRealm.permissionsLookupEnabled = true    
  jdbcRealm.authenticationQuery = SELECT password FROM users WHERE username = ?
  jdbcRealm.userRolesQuery = SELECT rolename FROM userroles WHERE username = ?

  jdbcRealm.permissionsQuery = SELECT permission FROM rolepermissions WHERE roleid=(SELECT roleid from roles where rolename= ? )

##connection pooling and database access through apache commons dbcp
  ds = org.apache.commons.dbcp.BasicDataSource
  ds.driverClassName = oracle.jdbc.driver.OracleDriver
  ds.username=nextgen
  ds.password =nextgen
  ds.url = jdbc:oracle:thin:@192.168.1.50:1521:orcl

##adding the data source to the realm earlier configured
  jdbcRealm.dataSource = $ds

##password encryption is done by sha256 encryption algorithm provided by shiro api
  Md5Matcher = org.apache.shiro.authc.credential.Md5CredentialsMatcher
  jdbcRealm.credentialsMatcher = $Md5Matcher

##configuring security manager to use the realm configured earlier
  securityManager.realms=$jdbcRealm

##Caching mechanism is dome by a third party chaching api called ehcache
##adding the chaching support to the security manager
  cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
  securityManager.cacheManager = $cacheManager 




[filters]
   shiro.loginUrl =/login

##url section is used to set permissions to specific urls
[urls]
    /language/** = anon
 /res/**= anon
               /theme/html/** = anon
               /theme/mobile/** = anon
               /view/mobile/login.html= anon
               /view/html/login/brokerDetailEnglish.html=anon
               /view/html/login/brokerDetailSinhala.html=anon
               /view/html/scripts/**=anon
                /view/mobile/scripts/**=anon
               /login.jsp = authc
               /view/html/home.jsp = authc, roles[user]
               /view/xml/home.jsp = authc, perms[users:xml:home]
               /** = authc


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>testP</display-name>

    <filter>
    <filter-name>ShiroFilter</filter-name>
    <filter-class>org.apache.shiro.web.servlet.IniShiroFilter</filter-class>
    <init-param>
      <param-name>configPath</param-name>
      <param-value>/WEB-INF/shiro.ini</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>ShiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <welcome-file-list>
    <welcome-file>login</welcome-file>
  </welcome-file-list>
  <servlet-mapping>
    <servlet-name>LoginCheckController</servlet-name>
    <url-pattern>/LoginCheckController</url-pattern>
    <url-pattern>/login</url-pattern>
  </servlet-mapping>  
</web-app>

【问题讨论】:

【参考方案1】:

请像这样更改您的表单操作

<form name="loginForm" method="post" action="login">

【讨论】:

以上是关于无法传递参数apache shiro jsp servlet的主要内容,如果未能解决你的问题,请参考以下文章

shiro loginUrl拦截无效

无法使用 Apache Shiro JDBC 设置登录,但访问限制有效

当我介绍 Apache SHIRO 时,为啥 .XHTML 文件试图调用 .JSP 文件?

Shiro学习JSP标签

shiro jsp标签使用

jsp输出shiro中session信息