JSP用户在Web基础应用程序中的身份验证

时间:2013-12-30 05:24:23

标签: java jsp web

    

    <title>Reprint</title>
    <style type="text/css">
        .btn_hover:hover{

            color: darkblue ;
        }

    </style>
    <%
        if (session.getAttribute("user") == null) {
            response.sendRedirect("login.jsp?ms=Please Login");
        }
    %>
</head>

<body onload="addDate();
        addDate1();
        addDate3();" style="background-color: aliceblue;" >
    <form action="search" method="Post" name="search">
        <table align="" border="1">
            <tr align="">
                <td  >
                    <h3 align="center" >Reprint Request Form <img  src="sarasavi.png" />  </h3>
                        <%
                            Date dNow = new Date();
                            SimpleDateFormat ft = new SimpleDateFormat(" yyyy.MM.dd");
                            out.print("<h4 align=\"center\">" + ft.format(dNow) + "</h4>");
                        %> 
                </td>
            </tr>
            <tr>
                <td>
                    <h6 >
                        Enter ISBN or Scan the Barcode <i style="color: #545454" class=" icon-barcode"></i>
                    </h6>
                    <input  type="text" placeholder="ISBN " name="isbn"/>
                    &nbsp;&nbsp;&nbsp;
                    <input type="submit" value="SEARCH" class="btn_hover"    style=" border-radius: 30px;" />  
                    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
                    <!--&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;-->

            <l style="font-size: 18px; font-weight: bold;">logged in as  </l><%
                ResultSet rs = (ResultSet) session.getAttribute("user");
                if (rs != null && rs.first()) {
                    ResultSet r4 = DB.search("Select * from User where uid='" + rs.getString("User_uid") + "'");
                    if (r4.next()) {
                %>
                <%=r4.getString("uName")%>
                <%
                        }
                    }
                %>
            <a href="Logout" style="font-weight: bold;">Log out</a>



            </td>

            </tr>

        </table>
    </form>


    <table border="1">
        <tr>
            <td>
                <ul class=" tabs left  " >
                    <li><a href="#tabr1" >Stores</a></li>
                    <li><a href="#tabr2">Publishing Department</a></li>
                    <li><a href="#tabr3">Printing Department</a></li>
                    <li><a href="#tabr4">Director</a></li>
                </ul>
                <!-- End Tabs -->

                <!-- Stores -->
                <form action="stores" method="Post" name="stores"> 
                    <div id="tabr1" class="tab-content">
                        <!-- HALF & HALF -->

                        <div class=" col_6">
                            <label for="text1" style=" font-size: 16px;">Title  </label><br/>
                            <input name="title" type="text" placeholder="Title" style="width: 355px; height: 28px;" /><br/><br/>

                            <label for="text2" style=" font-size: 16px;">Author  </label><br/>
                            <input name="author" type="text" placeholder="Author" style="width: 355px; height: 28px;" /><br/><br/>

                            <label for="text3" style=" font-size: 16px;">Price   </label></span> <br/>
                            <input name="price" type="text" placeholder="price" style="width: 95px; height: 28px;" /><br/><br/><br/>

                            <!-- Radio -->
                            <label style=" font-size: 16px;">Move</label><br/><br/>
                            <input type="radio" name="Move" id="radio1" value="Fast" />
                            <label for="radio1" class="inline"  >Fast</label><br/>
                            <input type="radio" name="Move" id="radio2" Value="Medium" />
                            <label for="radio2" class="inline">Medium</label><br/>
                            <input type="radio" name="Move" id="radio3" value="Slow" />
                            <label for="radio3" class="inline">Slow</label><br/>
                            <!-- Radio -->
                        </div>

                        <div class="col_6">


                            <label for="text4" style=" font-size: 16px;">Stock in hand </label> <br/>
                            <input name="stock" type="text" placeholder="" style="width: 100px; height: 28px;"  /><br/><br/>

                            <label style=" font-size: 16px;">Last GRN Date</label><br/>
                            <input type="date" name="date1" ><br/><br/>

                            <label for="text5" style=" font-size: 16px;">Last GRN Quantity </label></span> <br/>
                            <input name="Lastqty" type="text" placeholder="Qty" style="width: 100px; height: 28px;" /><br/><br/>

                            <label for="text4" style=" font-size: 16px;">Print Attempt </label> <br/>
                            <input name="attempt" type="text" placeholder="eg -: 3rd " style="width: 100px; height: 28px;" /><br/><br/><br/>

                            <input type="submit" value="Save"  class="btn_hover"/>&nbsp;&nbsp;
                            <input type="reset" value="Reset" class="btn_hover" />

                            <input name="p_id" type="text"   style="width: 100px; height: 28px; visibility:hidden;" />

                        </div>
                    </div>
                </form>
                <!-- Stores -->

                <!-- Publishing Department -->
                <form action="publishing" method="Post" name="publish" onsubmit="return(validate());">
                    <div id="tabr2" class="tab-content">
                        <div class="col_4">
                            <!-- Check box -->
                            <input type="checkbox" name="infrom" value="Informed" />
                            <label for="chek1" class="inline" style="font-size: 16px; font-weight: bold;" >Informed the Author </label><br/><br/><br/>
                            <!-- Check box -->
                            <!-- Table sortable -->
                            <label style="font-size: 18px; font-weight: bold;"> Last Print </label> <br/><br/>
                            <table width="500px" class="" style=" border: 1px; border-color: navy;"  >
                                <tr>
                                    <td colspan=6 align="center"
                                        style="background-color:teal">
                                        <b>Last Print</b></td>
                                </tr>
                                <tr style="background-color:lightgrey;">
                                    <td><b>Print</b></td>
                                    <td><b>Date</b></td>
                                    <td><b>Quantity</b></td>
                                    <td><b>Move</b></td>



                                </tr>
                                <%
                                    int count = 0;
                                    String color = "#F9EBB3";
                                    if (request.getAttribute("piList") != null) {
                                        ArrayList al = (ArrayList) request.getAttribute("piList");
                                        System.out.println(al);
                                        Iterator itr = al.iterator();
                                        while (itr.hasNext()) {

                                            if ((count % 2) == 0) {
                                                color = "#eeffee";
                                            }
                                            count++;
                                            ArrayList pList = (ArrayList) itr.next();
                                %>
                                <tr style="background-color:<%=color%>;">
                                    <td><%=pList.get(12)%></td>
                                    <td><%=pList.get(5)%></td>
                                    <td><%=pList.get(9)%></td>
                                    <td><%=pList.get(7)%></td>

                                <!--<input name="4" type="text" value=" <%=pList.get(6)%>" style="width: 100px; height: 28px;" />-->
                                </tr>
                                <%
                                        }
                                    }
                                    if (count == 0) {
                                %>
                                <tr>
                                    <td colspan=4 align="center"
                                        style="background-color:#eeffee"><b>No Record Found..</b></td>
                                </tr>
                                <%            }
                                %>
                            </table>
                            <!-- Table sortable -->
                            <br/><br/>
                            <label for="text6" style=" font-size: 16px;">Printer  </label><br/>
                            <select name="printer">
                                <%
                                    ResultSet rs3 = DB.search("Select * from printer_names");
                                    while (rs3.next()) {

                                        out.print("<option value=" + rs3.getString("printer_id") + " >" + rs3.getString("Printer_Name") + "</option>");
                                    }

                                %>
                            </select>
                            <a href="printer.jsp">  <input   type="button" value="Add a Printer" style="border-radius: 25px"  /></a>
                            <br/><br/>
                            <!-- Select -->
                            <label for="select1">Paper Type</label> <br/>
                            <select name="paper">
                                <option value="-1" selected="" >- Choose a Paper Type -</option>
                                <option value="1">Bank Paper</option>
                                <option value="2">Book Printing Paper </option>
                                <option value="3" >Art Paper</option>
                                <option value="4">Bulk</option>
                            </select>
                            <!-- Select -->
                            <br/><br/>
                            <label for="text7" style=" font-size: 16px;">Delivery for Printing  </label><br/>
                            <input name="Delivery" type="text" placeholder="Type here" style="width: 355px; height: 28px;" /><br/><br/>

                            <label for="text8" style=" font-size: 16px;">Quantity Suggested</label><br/>
                            <input name="qty" type="text" placeholder="Type here" style="width: 355px; height: 28px;" /><br/><br/> 
                        </div>

                        <div class="col_6" style="padding-left: 100px;">
                            <label style=" font-size: 16px;">Date</label><br/>
                            <input type="text" id="date1" name="date1" readonly="true " ><br/><br/> 

                            <label for="text9" style=" font-size: 16px;">Altered Page Numbers </label></span> <br/>
                            <input name="alt" type="text" placeholder="Eg-: 4 , 5 , 6 , 34" style="width: 355px; height: 28px;" /><br/><br/><br/>
                            <!-- Check box -->
                            <input  type="checkbox" name="sample" value="Given" id="cheksample" />
                            <label for="check2" class="inline" style="font-size: 16px; font-weight: bold;">Sample Copies </label><br/><br/><br/>
                            <!-- Check box -->
                            <label for="text10" style=" font-size: 16px;">Altered Tracing (No.s) </label> <br/>
                            <input name="alt_trac" type="text" placeholder="" style="width: 355px; height: 28px;" /><br/><br/>

                            <label style=" font-size: 16px;">Book Cover</label><br/><br/>
                            <input  type="radio" name="book_cvr" value="Same_Cover"  />
                            <label for="radio4" class="inline" >Same Cover</label><br/><br/>
                            <input type="radio" name="book_cvr" value="new_Cover" />
                            <label for="radio5" class="inline">New Cover</label><br/><br/><br/>

                            <input type="submit" value="Save" class="btn_hover"/>&nbsp;&nbsp;&nbsp;
                            <input type="reset" value="Reset" class="btn_hover" />

                        </div>

                    </div>


                </form>
                <!-- Publishing Department -->

                <!-- Printing Department -->
                <form action="Printing" method="Post"> 

                    <div id="tabr3" class="tab-content">
                        <div class="col_4">
                            <!-- Select2 -->
                            <label for="select2">Size</label> <br/>
                            <select id="select2" name="size">
                                <option value="0">- Choose a Size -</option>
                                <option value="SD 1/8">SD 1/8</option>
                                <option value="D 1/8">D 1/8</option>
                                <option value="D 1/4">D 1/4</option>
                                <option value="Cr 1/8">Cr 1/8</option>
                                <option value="Cr 1/4">Cr 1/4</option>
                                <option value="A4">A4</option>
                                <option value="A5">A5</option>
                                <option value="B4">B4</option>
                            </select><br/><br/><br/>
                            <!-- Select2 -->  
                            <label style="font-size: 18px; font-weight: bold;">No. of Pages</label><br/><br/>

                            <label>Black & White -</label>
                            <input type="text"  id="text11" name="BW" style="width: 100px; height: 28px;" ><br/><br/>

                            <label style="padding-right: 45px">Colour -</label>
                            <input type="text" id="text12 " name="clr" style="width: 100px; height: 28px;" ><br/><br/><br/>

                            <label style="font-size: 18px; font-weight: bold;"> Last Production Cost</label><br/><br/>
                            <!-- Table sortable2 -->
                            <table width="500px" class="" style=" border: 1px; border-color: navy;"  >
                                <tr>
                                    <td colspan=6 align="center"
                                        style="background-color:teal">
                                        <b>Last Production Cost</b></td>
                                </tr>
                                <tr style="background-color:lightgrey;">
                                    <td><b>Year</b></td>
                                    <td><b>Qty</b></td>
                                    <td><b>Cost</b></td>
                                    <td><b>Unit Cost</b></td>



                                </tr>
                                <%
                                    int count1 = 0;
                                    String color1 = "#F9EBB3";
                                    if (request.getAttribute("piList") != null) {
                                        ArrayList al = (ArrayList) request.getAttribute("piList");
                                        System.out.println(al);
                                        Iterator itr = al.iterator();
                                        while (itr.hasNext()) {

                                            if ((count % 2) == 0) {
                                                color = "#eeffee";
                                            }
                                            count++;
                                            ArrayList pList = (ArrayList) itr.next();
                                %>
                                <tr style="background-color:<%=color%>;">
                                    <td><%=pList.get(5)%></td>
                                    <td><%=pList.get(9)%></td>
                                    <td><%=pList.get(13)%></td>
                                    <td><%=pList.get(14)%></td>


                                </tr>
                                <%
                                        }
                                    }
                                    if (count == 0) {
                                %>
                                <tr>
                                    <td colspan=4 align="center"
                                        style="background-color:#eeffee"><b>No Record Found..</b></td>
                                </tr>
                                <%            }
                                %>
                            </table><br/><br/>
                            <!-- Table sortable2 -->

                            <label style="font-size: 18px; font-weight: bold;"> Estimated Printing Cost</label><br/><br/>

                            <label for="text13" style=" font-size: 16px;">Quantity</label> <br/>
                            <input id="text13" type="text" placeholder="" name="qty" style="width: 155px; height: 28px;" /><br/><br/>

                            <label for="text14" style=" font-size: 16px;">Cost</label> <br/>
                            <input id="text14" type="text" placeholder="" name="cost" style="width: 155px; height: 28px;" /><br/><br/>

                            <label for="text15" style=" font-size: 16px;">Unit Cost</label> <br/>
                            <input id="text15" type="text" placeholder=""  name="unit" style="width: 155px; height: 28px;"  /><br/><br/>
                        </div>
                        <div class="col_3">
                            <!-- Select3 -->
                            <label for="select2">Paper</label> <br/>
                            <select id="select3" name="paper">
                                <option value="0">- Choose a Paper -</option>
                                <option value="60 gsm">60 gsm</option>
                                <option value="70 gsm">70 gsm</option>
                                <option value="80 gsm">80 gsm</option>
                                <option value="100 gsm">100 gsm</option>
                                <option value="120 gsm">120 gsm</option>
                                <option value="150 gsm">150 gsm</option>
                            </select><br/><br/>
                            <!-- Select3 -->  
                            <!-- Select4 -->
                            <label for="select4">Binding</label> <br/>
                            <select id="select4" name="binding">
                                <option value="0">- Choose a Binding Methode   -</option>
                                <option value="Hard">Hard Binding</option>
                                <option value="Perfect">Perfect Binding</option>
                                <option value="Suddle">Suddle Binding</option>
                                <option value="Thread">Thread Binding/Perfect Binding</option>

                            </select><br/><br/>

                            <!-- Select4 -->  
                            <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
                            <input type="submit" value="Save"  class="btn_hover"/>&nbsp;&nbsp;&nbsp;
                            <input type="reset" value="Reset" class="btn_hover" />

                        </div>
                        <div class="col_3">
                            <label style=" font-size: 16px;">Date</label><br/>
                            <input type="text" id="date" readonly="true" name="date" ><br/><br/>

                        </div>
                    </div>
                    <!-- Printing Department -->
                </form>

                <!-- Director -->
                <form action="director" method="Post"> 
                    <div id="tabr4" class="tab-content">
                        <div class="col_6">
                            <label for="text16" style=" font-size: 16px;">Present Price  </label><br/>
                            <input name="present_price" type="text" placeholder="current Price" style="width: 355px; height: 28px;" /><br/><br/>
                            <label for="text17" style=" font-size: 16px;">Revise Price  </label><br/>
                            <input name="revise_price" type="text" placeholder="new Price" style="width: 355px; height: 28px;" /><br/><br/>
                            <label for="text18" style=" font-size: 16px;">Quantity   </label></span> <br/>
                            <input name="qty" type="text" placeholder="Qty" style="width: 355px; height: 28px;" /><br/><br/><br/>
                            <!--<input type="submit" value="Cancel" class="btn_hover" />&nbsp;&nbsp;-->
                            <!--<input type="reset" value="Reset" class="btn_hover" />-->
                        </div>
                        <div class="col_3">
                            <label style=" font-size: 16px;">Date</label><br/>
                            <input type="text" id="date3" readonly="true" name="date3" ><br/><br/><br/>

                            <label style=" font-size: 20px; font-weight: bolder;" class="inline">APPROVAL </label><br/><br/>
                            <input  type="radio" name="approval" value="APPROVED"  />
                            <label style=" font-size: 16px; font-weight: bold;"  class="inline" > Approved </label><br/><br/>
                            <input  type="radio" name="approval" value="NOT_APPROVED"  />
                            <label style=" font-size: 16px; font-weight: bold;"  class="inline" > Not Approved </label><br/><br/><br/><br/>

                            <input type="submit" value="OK"  class="btn_hover"/>&nbsp;&nbsp;
                        </div>
                        <div class="col_8">
                            <!-- Textarea -->
                            <label for="textarea1" style="font-size: 18px; font-weight: bold;"> Remark</label><br/>
                            <textarea name="remark" placeholder="Type Here" style="width: 650px; height: 200px;" ></textarea>
                        </div>
                    </div> 
                </form>
                <!-- Director -->

            </td>
        </tr>

    </table>
    <!-- Tabs  -->

</body>

`我使用jsp在Java中创建了一个小的webapp,并且在登录验证方面遇到了一些问题..

我有4个不同的用户。在jsp页面中有4个选项卡

我需要向他们提供对标签的有限访问权。

eg-director(可以看到所有标签)官员1(可以看到只有3个标签的访问权限)官2(可以看到只有2个标签的访问权限)官3(只能看到有1个访问标签)

这就像一个安全许可我尝试了很多方法而且失败了,我想通过将布尔值传递给数据库并为其提供访问级别,如果它是一个小样本日志,我需要帮助对我来说非常有用的项目

如果它可以用EER也可以,那就不错了

1 个答案:

答案 0 :(得分:-1)

在这种情况下,使用JSTL可能是你的好朋友! 假设servlet返回具有LEVEL

的登录用户的特权
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:if test="${LEVEL >= 4}">
   <p>director only page<p>
</c:if>
<c:if test="${LEVEL >= 3}">
   <p>officer 1 only page<p>
</c:if>
<c:if test="${LEVEL >= 2}">
   <p>officer 2 only page<p>
</c:if>
<c:if test="${LEVEL >= 1}">
   <p>officer 3 only page<p>
</c:if>

上面提供的代码只是一个框架,您需要将其中的<p>更改为您想要的tab