小项目-购物网站个别功能的具体实现思路-下(新手)

本文详细介绍了购物网站中修改密码的功能实现,包括用户从个人中心进入修改密码界面,填写新密码,Servlet处理数据的过程。此外,还讨论了过滤器的重要性和实现方法,探讨了其在网站开发中的应用。
摘要由CSDN通过智能技术生成

小项目-购物网站个别功能的具体实现思路-下(新手)


 

  • (11)修改密码

 

所需要的JSP页面(点击进入个人中心):

<div class="header_wrap">            
            <ul>
                <c:choose>
                    <c:when test="${empty W}">
                        <li><a href="/shop/views/login.jsp">登录</a></li>
                        <li><a href="/shop/views/register.jsp">注册</a></li>
                    </c:when>
                    <c:otherwise>
                        <li>欢迎您,尊敬的VIP:<a href="/shop/views/persional.jsp">${W.username}</a></li>
                    </c:otherwise>
                </c:choose>

个人中心JSP页面:

<body>
        <fieldset>
            <legend>
                欢迎来到您的个人中心
            </legend>
            <div>
                <ul>
                    <li><a href="/shop/LoginOut">注销当前账户</a></li>
                    <li><a href="/shop/home" >点击返回首页</a></li>
                    <li><a href="/shop/views/login.jsp">返回登陆界面</a></li>
                    <li><a href="/shop/views/update.jsp">点击修改密码</a></li>
                </ul>
            </div>

            <iframe name="show" width="65%" height="85%"></iframe>
        </fieldset>
</body>

修改密码的JSP界面:

<body>

<div class="wrap">
    <div class="guimeilogo"></div>
    <div class="login">
        <div class="top">
            <h1>个人信息</h1>
            <a href="">修改界面</a>
        </div>

        <div class="mid">
            <form action="/shop/update" method="post">
                <input type="password" name="password"  placeholder="原密码" required="required" />
                <input type="password" name="passwords"  placeholder="新密码" required="required" />
                ${Lxr}
                <input type="submit" id="submit" value="立即修改"/>
                ${C}
            </form>
        </div>
    </div>
</div>
</body>

所需要的Servlet:

@WebServlet("/update")
public class UpdateServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
     // 读写当前的登录信息。
        Map w = (Map) req.getSession().getAttribute("W");
     
    
     // 获得请求参数 Object password1
= w.get("password");// 获得user表中的原密码类型 String password = req.getParameter("password");// 获取现在登录状态的原密码 String passwords = req.getParameter("passwords");// 修改过后的密码 Integer uid = (Integer) w.get("uid");// 用户的ID

     // 两者做比较(equals比较的是字符串内容)如果成功则重定向到登录界面
if (password.equals(password1)){ IUserDAO dao = new UserDAOImpl(); dao.UpdatePassword(passwords,uid); resp.sendRedirect("/shop/views/login.jsp");
     // 否则提示更改失败,重定向到更改界面。 }
else{ req.setAttribute("Lxr","更改失败"); req.getRequestDispatcher("/update.jsp").forward(req,resp); } } }

流程:

    用户点击主界面的个人昵称进入个人中心-在个人中心点击修改密码-进入修改密码的JSp页面,填写提交新的信息-Servlet接收数据处理数据-重定向到登录的JSP页面


 

 

 

 

 

 


  • (12)过滤器

过滤器的作用和意义:

在Servlet作为过滤器使用时,它可以对客户的请求进行处理。处理完成后,它会交给下一个过滤器处理,这样,客户的请求在过滤链里逐个处理,直到请求发送到目标为止。

例如,某网站里的功能,有很多界面有验证“是否登录”业务,如果使用过滤器的话就可以简化很多本来需要在Servlet中写入的代码段。化繁为简。

这两项工作可以在由两个过滤器组成的过滤链里进行处理。当过滤器处理成功后,把提交的数据发送到最终目标;如果过滤器处理不成功,将把视图派发到指定的错误页面。

过滤器的写法:

@WebFilter("*.do")
public class CharacterEncodingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("过滤器正在启动。");
        System.out.println("过滤器正在初始化!");
    }
  

   //在这个方法里面写。 @Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { System.out.println("-------------------过滤器开始工作!-------------------"); //设置编码格式。 request.setCharacterEncoding("UTF-8"); //获取账号密码的关键字信息。 HttpServletResponse resp = (HttpServletResponse) response; HttpServletRequest req = (HttpServletRequest) request; Map w = (Map) req.getSession().getAttribute("W"); //如果没有登录则重定向到登录界面 if (w == null){ resp.sendRedirect("/shop/views/login.jsp"); System.out.println("-------------------过滤器拦截成功!-------------------"); }else { //放行数据。 filterChain.doFilter(req,resp); } } @Override public void destroy() { System.out.println("我被销毁啦。"); } }

实现过滤的方法:

*.do    意为:
                    所有@WebServlet的映射路径带.do的都会进行拦截。
                    例如:/scart.do、/Addcart.do

 

posted @ 2019-04-23 21:59 浪子。 阅读( ...) 评论( ...) 编辑 收藏
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
网上购物系统 摘 要 本文通过分析国内外网上购物系统的发展现状,提出了一种利用asp技术开发网上购物系统的方案,以期达到功能强大,费用低廉,通用性强,适合我国国情的购物网站系统。文中着重论述了该系统的功能实现、数据流程与存储、网上购物、后台管理等 经分析,使用Microsoft公司的ASP(Active Server Pages)和相关网页开发工具,利用微软提供的IIS建立运行环境,再利用ODBC(数据源)建立数据连接关系。利用其提供的各种组件及内置对象,首先在短时间内建立数据库,然后,对数据库进行分析与建立ASP页面,不断修正与改进,直到功能基本实现的可行性购物系统。 关键词: 购物系统 ASP技术 电子商务 Abstract This article through analyzes the domestic and foreign on-line shopping system the development present situation, proposed one kind operates on the hairnet using the asp technology the shopping system plan, to the time achieved function formidable, expense inexpensive, the versatility is strong, suits our country national condition the shopping website system. In the article emphatically elaborated this system function and the realization, the data flow and the memory, the on-line shopping, the backstage management and so on. After the analysis, uses Microsoft Corporation ASP (Active Server Pages) and the correlation homepage development kit, provides the Disestablishment movement environment using Microsoft, again (data pool)establishes the data connection relations using ODBC. Each kind of module provides which using it and in sets at the object, first establishes the database in the short time, then, carries on to the database analyzes and establishes the ASP page, unceasingly revises and the improvement, until function basic realization feasible shopping system. KEYWORD:Shopping system ASP technology Electronic commerce 毕业设计+源码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值