如何在用户登录到jsp后禁用html控件 [英] How to disable html controls after a user logins in jsp

查看:95
本文介绍了如何在用户登录到jsp后禁用html控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是情况..
1.我有一个主页,其中包含登录|的选项注册|联系|关于我 in jsp ..
2.它基本上是一个在线购物网站..
3.当用户访问该网站时,登录|注册| 应该是可见的,但是当用户用他的用户ID登录并且通过他的用户名和注销按钮应该替换登录和注册链接。

Here's the situation.. 1. I got a home page with options of Login | Register | Contact | About me in jsp.. 2. Its basically a online shopping website.. 3. When the user visits the website.. the Login | Register | should be visible, but when a user logs in with his user id and pass his Username and logout button should replace the Login and Register links..

例如..
共同主页:登录|注册|联系|关于我

登录主页:欢迎abcde |注销|联系|关于我

我没有得到它的逻辑...如果sme 1可以证明我会有很大的帮助。

i am not getting the logic of it... if sme 1 can demonstrate me it will be of great help.

推荐答案

您可以通过以下方式执行此操作。

You can do this in following way..

 <body>
        <ul id="nav">
            <li><a href="/home.jsp">Home</a></li>
            <li><a href="/aboutus.jsp">About</a></li>
            <li><a href="/contactus.jsp">Contact</a></li>
            <%
                String username= (String) session.getAttribute("user");                     
                if (username == null) {
            %>
            <li><a href="/register.jsp">Register</a></li>
            <li><a href="/login.jsp">Login</a></li>

        <% } else {
         %>
            <li>Hi, <%=username %>  (<a href="/logout.jsp">Logout</a>)</li>
        <% }%>
        </ul>
    </body>

并在您的servlet中放入此代码

and in your servlet put this code

  HttpSession session = request.getSession(true);
  String user = request.getParameter("username");
  session.setAttribute("user", name);

这篇关于如何在用户登录到jsp后禁用html控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆