3.15~3.21学习周报

项目场景1:过滤器课程作业


问题描述:

在过滤器章节的作业,出现了过滤器正常运行,但运行后却无法跳转至期望页面的现象。
@Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("过滤器开始");
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        request.setCharacterEncoding("utf-8");
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        //仅限登录用户访问
        String URI = request.getRequestURI();
        HttpSession session = request.getSession();
        Object username = session.getAttribute("username");
        if ((URI.endsWith("download.jsp") && username == null) || (URI.endsWith("comment.jsp") && username == null)) {
            response.sendRedirect("index.jsp");
        }
        System.out.println("过滤器结束");
    }

在这里插入图片描述
在这里插入图片描述


原因分析:

原因是缺少了关键的语句
...
filterChain.doFilter(request,response);
...

在听课的时候老师说这个方法的作用是如果存在第二个过滤器,则会在第一个过滤器结束之前调用第二个过滤器。
但实际上,只有一个过滤器的时候,如果缺少了这个语句,就会导致上述现象的出现。猜测是因为这个函数除了老师所说的功能外,还有跳出过滤器执行过程的功能。无论有几个过滤器,都要加入这个语句,确保过滤器进行过滤后,还能回到主流程继续进行操作。


解决方案:

在doFilter方法的最后加入’filterChain.doFilter(request,response);‘

@Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("过滤器开始");
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        request.setCharacterEncoding("utf-8");
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        //仅限登录用户访问
        String URI = request.getRequestURI();
        HttpSession session = request.getSession();
        Object username = session.getAttribute("username");
        if ((URI.endsWith("download.jsp") && username == null) || (URI.endsWith("comment.jsp") && username == null)) {
            response.sendRedirect("index.jsp");
        }
        System.out.println("过滤器结束");
        filterChain.doFilter(request,response);
    }

即可进行正常跳转


项目场景2:AJAX课程作业


问题描述:

在这里插入图片描述
做了这样一个作业,效果是使用AJAX技术,达到点击点赞按钮,动态更新点赞总数的效果。
但是出现了点击按钮,无法更新总数的现象。
浏览器中按F12,报错如下
在这里插入图片描述
是程序中出现了错误


原因分析:

NumberFormatException,数字格式化异常,指向了源代码中的doPost方法
@Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String oneClick = req.getParameter("oneClick");
        int point = Integer.parseInt(oneClick);
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        writer.print(point + 1);
    }

但实际上,doPost方法并没有出什么问题,至少应该说,逻辑上并没有出什么问题。那就是说,从oneClick属性中获取的参数有问题。
oneClick参数是通过js代码设置的

<script src="js/jquery-3.5.0.min.js"></script>
  <script>
    $(function(){
      $("#powerUp").click(function () {
        var point = $("#point").val();
        $.post("powerUp","oneClick=" + point,function(rs){
          $("#point").html(rs);
        })
      })
    })
  </script>

其中,point事件来自:

<img src="img/班尼特觉得很赞.jpg" id="1">
    <button id="powerUp"><img src="img/热情过载.png" id="2"></button>
    获得力量:<span id="point">0</span>

最后通过咨询老师得知,要获取span标签中的内容,不能使用val()方法,要用text()方法。
非常无语的错误- -,都怪自己前端课程学艺不精


解决方案:

将val()方法替换为text()方法即可使程序正常运行
<script src="js/jquery-3.5.0.min.js"></script>
  <script>
    $(function(){
      $("#powerUp").click(function () {
        var point = $("#point").text();
        $.post("powerUp","oneClick=" + point,function(rs){
          $("#point").html(rs);
        })
      })
    })
  </script>

项目场景:MVC框架之拼写检查的重要性


问题描述:

在跟随课程视频编写MVC框架时,遇到了这个问题

在这里插入图片描述
说servlet初始化出现问题,因为流参数是空的

public class DispatcherServlet extends HttpServlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
        String path = config.getInitParameter("contentConfigLocation");//指向了application.properties
        //在类加载的时候通过ClassLoader读取配置文件
        InputStream is = DispatcherServlet.class.getClassLoader().getResourceAsStream(path);
//        Properties ppt = new Properties();//创建一个ppt对象用于解析ppt类型的输入流
//        try {
//            ppt.load(is);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }//重复的流读取操作会使后面读取同源的流时读不到内容
        HandlerMapping.load(is);
    }
<servlet>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>com.ywy.mvc.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contentConfigLocation</param-name>
            <param-value>application.properties</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>DispatcherServlet</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

但实际上参数的映射写的也没有问题,指向了application.properties文件


原因分析:

这波只能说操作不够细节 当我检查过程序里流的路劲,检查过web.xml文件里的映射,发现都没有问题,甚至怀疑起了是不是因为我项目设置哪里有问题,导致了我Propertie对象的load方法执行过程跟正常的有点不一样。

这时旭哥出现了:“你单词写错了”

在这里插入图片描述
。。。。。。。如听仙乐耳暂明

有点无语,这种错误跟把adidas写成abibas差不多一个水平了

所以以后再出现这种错误的时候,就要学会扩大一些检查范围。

越是觉得不可能犯错的地方,往往越容易犯错。


解决方案:

改名

总结:

看起来都是些无关紧要的小错误,没有什么大的技术性的问题,我不知道我是不是应该高兴一下。

之后写程序要更加细心一点才行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
用MATLAB计算波动率,股票历史价格为3.64 3.61 3.58 3.6 3.59 3.57 3.58 3.6 3.57 3.52 3.49 3.48 3.45 3.43 3.46 3.47 3.49 3.54 3.53 3.5 3.52 3.55 3.42 3.42 3.43 3.44 3.39 3.38 3.41 3.42 3.37 3.44 3.4 3.42 3.41 3.42 3.42 3.39 3.26 3.16 3.18 3.21 3.16 3.24 3.25 3.26 3.26 3.23 3.27 3.32 3.3 3.26 3.25 3.26 3.18 3.22 3.18 3.11 3.14 3.18 3.2 3.13 3.16 3.15 3.14 3.21 3.2 3.21 3.25 3.28 3.25 3.24 3.29 3.28 3.23 3.19 3.17 3.2 3.16 3.16 3.19 3.25 3.25 3.25 3.23 3.3 3.31 3.3 3.33 3.31 3.33 3.27 3.29 3.29 3.31 3.35 3.35 3.33 3.29 3.29 3.3 3.29 3.25 3.22 3.24 3.24 3.23 3.22 3.21 3.28 3.26 3.26 3.26 3.24 3.21 3.25 3.25 3.26 3.27 3.25 3.22 3.18 3.16 3.18 3.19 3.21 3.22 3.25 3.3 3.35 3.35 3.35 3.34 3.3 3.32 3.27 3.24 3.26 3.24 3.28 3.27 3.27 3.29 3.22 3.25 3.26 3.25 3.24 3.19 3.21 3.22 3.2 3.22 3.17 3.12 3.13 3.17 3.17 3.21 3.21 3.19 3.13 3.14 3.11 3.04 3.1 3.1 3.12 3.13 3.12 3.09 3.1 3.12 3.12 3.14 3.13 3.08 3.1 3.04 3.06 3.06 3.11 3.09 3.08 3.05 2.95 2.91 2.89 2.91 2.92 2.83 2.69 2.81 2.86 2.89 2.87 2.88 2.9 2.88 2.84 2.84 2.82 2.9 2.88 2.92 2.91 2.88 2.91 2.83 2.88 2.87 2.91 2.91 2.87 2.84 2.82 2.78 2.8 2.66 2.66 2.71 2.75 2.79 2.78 2.7 2.68 2.7 2.72 2.7 2.73 2.7 2.74 2.73 2.73 2.79 2.76 2.72 2.72 2.72 2.74 2.76 2.79 2.78 2.78 2.81 2.83 2.86 2.85 2.89 2.84 2.87 2.91 2.89 2.93 2.92 2.93 2.9 2.94 2.98 3.02 3.04 3.02 3.07 3.06 3.06 3.06 3.01 3 3.01 2.96 2.94 2.93 2.91 2.87 2.91 2.9 2.91 2.87 2.89 2.88 2.89 2.87 2.87 2.83 2.82 2.77 2.75 2.78 2.82 2.8 2.8 2.77 2.83 2.84 2.82 2.81 2.82 2.8 2.79 2.79 2.77 2.75 2.79 2.79 2.77 2.77 2.8 2.78 2.75 2.74 2.76 2.75 2.75 2.8 2.81 2.79 2.78 2.72 2.72 2.71 2.69 2.67 2.67 2.65 2.68 2.65 2.65 2.65 2.59 2.58 2.59 2.56 2.63 2.62 2.61 2.56 2.54 2.53 2.44 2.43 2.44 2.42 2.37 2.33 2.44 2.46 2.42 2.51 2.52 2.5 2.48 2.48 2.56 2.58 2.63 2.62 2.6 2.59 2.56 2.57 2.58 2.56 2.59 2.54 2.65 2.64 2.63 2.62 2.68 2.69 2.67 2.68 2.71 2.68 2.68 2.7 2.68 2.69 2.65 2.61 2.61 2.63 2.62 2.61 2.64 2.65 2.63 2.65 2.65 2.66 2.71 2.72 2.75 2.74 2.75 2.75 2.8 2.85 2.84 2.82 2.83 2.85 2.85 2.82 2.83 2.82 2.78 2.74 2.75 2.74 2.77 2.76 2.78 2.79 2.76 2.75 2.72 2.8 2.81 2.78 2.77 2.74 2.73 2.75 2.78 2.78 2.78 2.75 2.72 2.7 2.68 2.64 2.67 2.65 2.65 2.63 2.64 2.62 2.65 2.66 2.67 2.66 2.64 2.64 2.64 2.67 2.67 2.67 2.68 2.67 2.69 2.69 2.68 2.67 2.67 2.68 2.74 2.75 2.72 2.71 2.66 2.62 2.62 2.62 2.66 2.68 2.69 2.69 2.72 2.71 2.67 2.67 2.63 2.68 2.67 2.65 2.64 2.63 2.66 2.62 2.58 2.57 2.56 2.55 2.54 2.5 2.51
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值