简体   繁体   English

JSP中的登录身份验证和会话

[英]Login Authentication and session in JSP

'

<head>

    <title>Reprint</title>    

    <script>

        function addDate1() {
            date1 = new Date();
            var month = date1.getMonth() + 1;
            var day = date1.getDate();
            var year = date1.getFullYear();

            if (document.getElementById('date1').value == '') {
                document.getElementById('date1').value = year + '-' + month + '-' + day;
            }
        }
        function addDate() {
            date = new Date();
            var month = date.getMonth() + 1;
            var day = date.getDate();
            var year = date.getFullYear();

            if (document.getElementById('date').value == '') {
                document.getElementById('date').value = year + '-' + month + '-' + day;
            }
        }
    </script>
    <style type="text/css">
        .btn_hover:hover{

            color: darkblue ;
        }

    </style>
</head>
<body onload="addDate();
            addDate1()" style="background-color: aliceblue;" >
    <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 id="isbn" type="text" placeholder="ISBN "/>

            </td>
        </tr>

    </table>

    <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="####" method="Post"> 
                    <div id="tabr1" class="tab-content">
                        <!-- HALF & HALF -->

                        <div class=" col_6">
                            <label for="text1" style=" font-size: 16px;">Title  </label><br/>
                            <input id="text1" type="text" placeholder="Title" style="width: 355px; height: 28px;" /><br/><br/>
                            <label for="text2" style=" font-size: 16px;">Author  </label><br/>
                            <input id="text2" type="text" placeholder="Author" style="width: 355px; height: 28px;" /><br/><br/>
                            <label for="text3" style=" font-size: 16px;">Price   </label></span> <br/>
                            <input id="text3" 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="radio" id="radio1" />
                            <label for="radio1" class="inline">Fast</label><br/>
                            <input type="radio" name="radio" id="radio2" />
                            <label for="radio2" class="inline">Medium</label><br/>
                            <input type="radio" name="radio" id="radio3" />
                            <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 id="text4" type="text" placeholder="" style="width: 100px; height: 28px;" /><br/><br/>
                            <label style=" font-size: 16px;">Last GRN Date</label><br/>
                            <input type="date" ><br/><br/>
                            <label for="text5" style=" font-size: 16px;">Last GRN Quantity </label></span> <br/>
                            <input id="text5" type="text" placeholder="Qty" style="width: 100px; height: 28px;" /><br/><br/><br/>

                            <input type="submit" value="Save"  class="btn_hover"/>&nbsp;&nbsp;
                            <input type="submit" value="Reset" class="btn_hover" />
                        </div>
                    </div>
                </form>
                <!-- Stores -->

                <!-- Publishing Department -->
                <form action="####" method="Post">
                    <div id="tabr2" class="tab-content">
                        <div class="col_4">
                            <!-- Check box -->
                            <input type="checkbox" id="check1" />
                            <label for="check1" 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 class="sortable" border='1'>
                                <thead><tr>
                                        <th>Print</th>
                                        <th>Date</th>
                                        <th>Quantity</th>
                                    </tr></thead>
                                <tbody>
                                    <tr>
                                        <td>Item1</td>
                                        <td>Item2</td>
                                        <td>Item3</td>
                                    </tr>
                                    <tr>
                                        <td>Item1</td>
                                        <td>Item2</td>
                                        <td>Item3</td>
                                    </tr>
                            </table>
                            <!-- Table sortable -->
                            <br/><br/>
                            <label for="text6" style=" font-size: 16px;">Printer  </label><br/>
                            <input id="text6" type="text" placeholder="Type Printer Name" style="width: 355px; height: 28px;" /><br/><br/>
                            <!-- Select -->
                            <label for="select1">Paper Type</label> <br/>
                            <select id="select1">
                                <option value="0">- 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 id="text7" type="text" placeholder="Type here" style="width: 355px; height: 28px;" /><br/><br/>

                            <label for="text8" style=" font-size: 16px;">Quantity Suggested</label><br/>
                            <input id="text8" 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" readonly="true " ><br/><br/> 
                            <label for="text9" style=" font-size: 16px;">Altered Page Numbers </label></span> <br/>
                            <input id="text9" type="text" placeholder="Eg-: 4 , 5 , 6 , 34" style="width: 355px; height: 28px;" /><br/><br/><br/>
                            <!-- Check box -->
                            <input type="checkbox" id="check2" />
                            <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 id="text10" type="text" placeholder="" style="width: 355px; height: 28px;" /><br/><br/>

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

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

                    </div>

                </form>
                <!-- Publishing Department -->
                <form action="####" method="Post"> 
                    <!-- Printing Department -->
                    <div id="tabr3" class="tab-content">
                        <div class="col_4">
                            <!-- Select2 -->
                            <label for="select2">Size</label> <br/>
                            <select id="select2">
                                <option value="0">- Choose a Size -</option>
                                <option value="1">SD 1/8</option>
                                <option value="2">D 1/8</option>
                                <option value="3">D 1/4</option>
                                <option value="4">Cr 1/8</option>
                                <option value="5">Cr 1/4</option>
                                <option value="6">A4</option>
                                <option value="7">A5</option>
                                <option value="8">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"style="width: 100px; height: 28px;" ><br/><br/>
                            <label style="padding-right: 45px">Colour -</label>
                            <input type="text" id="text12 "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 class="sortable" border='1'>
                                <thead><tr>
                                        <th>Year</th>
                                        <th>Qty</th>
                                        <th>Cost</th>
                                        <th>Unit Cost</th>
                                    </tr></thead>
                                <tbody>
                                    <tr>
                                        <td>Item1</td>
                                        <td>Item2</td>
                                        <td>Item3</td>
                                        <td>Item4</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="" style="width: 155px; height: 28px;" /><br/><br/>
                            <label for="text14" style=" font-size: 16px;">Cost</label> <br/>
                            <input id="text14" type="text" placeholder="" style="width: 155px; height: 28px;" /><br/><br/>
                            <label for="text15" style=" font-size: 16px;">Unit Cost</label> <br/>
                            <input id="text15" type="text" placeholder="" style="width: 155px; height: 28px;" readonly="true" /><br/><br/>
                        </div>
                        <div class="col_3">
                            <!-- Select3 -->
                            <label for="select2">Paper</label> <br/>
                            <select id="select3">
                                <option value="0">- Choose a Paper -</option>
                                <option value="1">60 gsm</option>
                                <option value="2">70 gsm</option>
                                <option value="3">80 gsm</option>
                                <option value="4">100 gsm</option>
                                <option value="5">120 gsm</option>
                                <option value="6">150 gsm</option>
                            </select><br/><br/>
                            <!-- Select3 -->  
                            <!-- Select4 -->
                            <label for="select4">Binding</label> <br/>
                            <select id="select4">
                                <option value="0">- Choose a Binding Methode   -</option>
                                <option value="1">Hard Binding</option>
                                <option value="2">Perfect Binding</option>
                                <option value="3">Suddle Binding</option>
                                <option value="4">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="submit" 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" ><br/><br/>

                        </div>
                    </div>
                    <!-- Printing Department -->
                </form>
                <form action="####" method="Post"> 
                    <div id="tabr4" class="tab-content">
                        <div class="col_6">
                            <label for="text16" style=" font-size: 16px;">Present Price  </label><br/>
                            <input id="text16" type="text" placeholder="current Price" style="width: 355px; height: 28px;" /><br/><br/>
                            <label for="text17" style=" font-size: 16px;">Revise Price  </label><br/>
                            <input id="text17" type="text" placeholder="new Price" style="width: 355px; height: 28px;" /><br/><br/>
                            <label for="text18" style=" font-size: 16px;">Quantity   </label></span> <br/>
                            <input id="text18" type="text" placeholder="Qty" style="width: 355px; height: 28px;" /><br/><br/><br/>

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

            </td>
        </tr>

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

</body>

'

i have made a little webapp in Java using jsp and am having a little problem with Login Authentication.. 我已经使用jsp在Java中制作了一个小的webapp,并且登录身份验证遇到了一些问题。

  1. i have 4 different users. 我有4个不同的用户。 have 4 tabs in a jsp page 一个jsp页面中有4个选项卡

  2. i need to give them the limited access to Tabs. 我需要给他们有限的标签访问权限。

eg-director (can see all the tabs) officer 1 (can see only have accesses to 3 of tabs ) officer 2 (can see only have accesses to 2 of tabs ) officer 3 (can see only have accesses to 1 of tabs ) 例如,主任(可以看到所有选项卡)主任1(只能看到3个选项卡的访问权限)主任2(只能看到2个选项卡的访问权限)主任3(只能看到1个选项卡的访问权限)

it is like a security clearance i tried to so many ways and failed and i am thinking to do that with passing a Boolean to Database and give the access levels for that i need a help if it is with a small sample log in project that will be very help full for me 这就像一个安全检查,我尝试了很多方法但都失败了,我正在考虑通过将布尔值传递给数据库并为此提供访问级别来实现这一点,如果它是一个小型示例登录项目,非常帮我忙

Try this way out, 尝试这种方式,

After successful login, save user type in session. 成功登录后,将用户类型保存在会话中。 Then in jsp add following conditions for role. 然后在jsp中添加以下角色角色。

let's say for example, We want to block access of Tab 4 for 'officer 2'. 举例来说,我们要禁止访问“人员2”的选项卡4。
Then in jsp for Tab 4 , add below condition. 然后在用于选项卡4的jsp中,添加以下条件。 and like wise in other jsp's also. 就像其他jsp中的明智者一样。

<c:if test="${role== 'officer 2'}">
  <jsp: forward page="../invalidAccess.html"/>
</c:if>

alternatively, You can make use of Filters to do same. 或者,您可以使用过滤器执行相同的操作。 Filters are more preferred over earlier way. 过滤器比早期方法更可取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM