会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132600个问题
JAVA 全系列/第一阶段:JAVA 快速入门/面向对象详解和JVM底层内存分析 24286楼
JAVA 全系列/第六阶段:项目管理与SSM框架/SpringMVC 24287楼

image.png

servletdemo.rar

老师,包给你了,帮我看一下

JAVA 全系列/第五阶段:JavaWeb开发/Servlet技术详解(旧) 24288楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>百度搜索案例</title>
    <style>
        *{margin: 0;padding: 0;}
        input{width: 295px;height: 30px;margin: 0 auto;display: block;border: 1px solid lightgray;margin-top: 100px;padding-left: 5px;}
        ul{list-style: none;width: 302px;margin: 0 auto;display: none;}
        ul li{border: 1px solid lightgray;}
    </style>
</head>
<body>
    <input type="text" id="inputSearch">
    <ul id="ulList">
        <li>123</li>
    </ul>
    <script>
        function callbackDemo(response){
            var oUl = document.getElementById('ulList');
            var html = '';
            if(response.s.length != 0){
                oUl.style.display = 'block';
                for(var i=0; i<response.s.length; i++){
                    html += '<li>'+response.s[i]+'</li>'
                }
            }
            oUl.innerHTML = html;
        }
        window.onload = function(){
            var oData = document.getElementById('inputSearch');
            var oUl = document.getElementById('ulList');
            oData.onkeyup = function(){
                if(oData.value != ''){
                    var script = document.createElement('script');
                    script.scr = 'https://suggestion.baidu.com/su?wd='+this.value+'&cb=callbackDemo';
                    document.body.appendChild(script);
                }else{
                    oUl.style.display = 'none';
                }
            }
        }
    </script>
</body>
</html>

老师,我这个也不报错,就是不出来

WEB前端全系列/第六阶段:Http服务与Ajax模块(旧)/Http服务与Ajax编程 24290楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/IO 流技术(旧) 24291楼

二进制文件读取.png

老师,这里为什么是报的语法错误?

Python 全系列/第二阶段:Python 深入与提高/文件处理 24292楼
JAVA 全系列/第一阶段:JAVA 快速入门/飞机大战小项目训练 24294楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 24295楼

flask_shop_st.zip


老师您帮我看一下吧,我自己改错误,改着改着就多出来一个.实在是解决不了


image.png

Python 全系列/第十阶段:Flask百战电商后台项目/Flask百战电商后台项目 24296楼

package com.bjsxt.shiro02;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;

public class TestB {
    public static void main(String[] args) {
        //[1]解析shiro.ini 文件
        IniSecurityManagerFactory factory =new IniSecurityManagerFactory("classpath:shiro04-jdbc.ini ");
        //[2]通过SecurityManager 工厂获得SecurityManager 实例
        SecurityManager securityManager = factory.getInstance();
        //[3]用SecurityUtils把SecurityManager 对象设置到运行
        SecurityUtils.setSecurityManager(securityManager);
        //[4]通过SecurityUtils 获得主体 subject
        Subject subject = SecurityUtils.getSubject();
        //[5]书写自己输入的账号和密码---相当于用户自己输入的账号和密码
//我们拿着自己书写用户名密码去和shiro.ini 文件中的账号密码比较
        UsernamePasswordToken token = new UsernamePasswordToken("root","root");
        try {
            //[6]进行身份的验证
            subject.login(token);
            //[7]通过方法判断是否登录成功
            if (subject.isAuthenticated()) {
                System.out.println("登录成功");
            }
        }catch (IncorrectCredentialsException e){
            System.out.println("凭证(密码)不正确");
        }catch (UnknownAccountException e1){
            System.out.println("用户名不正确");
        }catch (ExpiredCredentialsException e){
            System.out.println("凭证过期");
        }catch (ExcessiveAttemptsException e){
            System.out.println("尝试次数过多");
            e.printStackTrace();
        }catch (ConcurrentAccessException e){
            System.out.println("竞争次数过多");
        }
    }
}

自定义Realm文件

package com.bjsxt.shiro02;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * 自定义Realm
 */

/**
 * 授权
 */
public class UserRealm extends AuthorizingRealm {
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    /**
     * 认证
     * @param authenticationToken
     * @return
     * @throws AuthenticationException
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        try{
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/shiro","root","zjx666888");
            PreparedStatement preparedStatement = conn.prepareStatement("select uname,pwd from user");
            ResultSet rs = preparedStatement.executeQuery();
            while (rs.next()){
                //把查到的数据集合给这个对象
                SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(rs.getString("uname"),rs.getString("pwd"),"real");
                return info;
            }

        }catch (Exception e){
        }
        return null;
    }


}

ini配置文件

image.png


数据库内容

image.png

image.png


老师为什么我输入sxt和123就可以登录成功,输入其他的就是密码错误??????????????


image.png

JAVA 全系列/第九阶段:权限控制与安全认证/Shiro(旧) 24297楼
JAVA 全系列/第八阶段:Linux入门到实战/Maven 24300楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637