0

以下は私のjspファイルです。値を処理してjspページに値を表示したら。値はサーブレットから取得されますが、次にURLを入力すると、以前にあった値が表示されるので、これを行う方法を提案してください。

jspコードは次のとおりです。

<%@ page contentType="text/html"%>
<%@ page pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<%
       Map<String, String> reportMap = new LinkedHashMap<String, String>();
        if (session.getAttribute("leaveMap") != null) {
            reportMap = (Map<String,String>) session.getAttribute("leaveMap");
        }
        String classname="",employeeid="",employeename="";
        int style =0,sno=1;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Comparing access-card Data with leave manager Data</title>
<link href="css/sling.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src='script/cal.js'></script>
<!-- Below imports for Blanket purpose-->
<script src='script/blanket.js'></script>

<script>
    var _validFileExtensions = [".xls"];

    function Validate(oForm) {
        var arrInputs = oForm.getElementsByTagName("input");
        var filename = document.getElementById("myFile");
        if(filename.value.length ==0){
            alert("Please select the file to upload");
            return false;
        }else{
            for (var i = 0; i < arrInputs.length; i++) {
                var oInput = arrInputs[i];
                if (oInput.type == "file") {
                    var sFileName = oInput.value;
                    if (sFileName.length > 0) {
                        var blnValid = false;
                        for (var j = 0; j < _validFileExtensions.length; j++) {
                            var sCurExtension = _validFileExtensions[j];
                            if (sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length).toLowerCase() == sCurExtension.toLowerCase()) {
                                blnValid = true;
                                break;
                            }
                        }

                        if (!blnValid) {
                            alert("Sorry, " + sFileName + " is invalid, allowed extensions are: " + _validFileExtensions.join(", "));

                            return false;
                        }
                    }
                }
            }
        }

        return true;
    }


        function isValidDate(element){
            var elementValue = element.value;
            var daysInMonth = DaysArray(12);
            var pos1=elementValue.indexOf(dtCh)
            var pos2=elementValue.indexOf(dtCh,pos1+1)
            var strDay=elementValue.substring(0,pos1)
            var strMonth=elementValue.substring(pos1+1,pos2)
            var strYear=elementValue.substring(pos2+1)
            strYr=strYear
            if (strDay.charAt(0)=="0" && strDay.length>1)
                strDay=strDay.substring(1)
            if (strMonth.charAt(0)=="0" && strMonth.length>1)
                strMonth=strMonth.substring(1)
            for (var i = 1; i <= 3; i++) {
                if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
            }
            month=parseInt(strMonth)
            day=parseInt(strDay)
            year=parseInt(strYr)
            if(elementValue!="") {
                if (pos1==-1 || pos2==-1){
                    return errorMessage("The date format should be : dd/mm/yyyy", element);
                }
                if (strMonth.length<1 || month<1 || month>12){
                    return errorMessage("Please enter a valid month", element);
                }
                if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
                    return errorMessage("Please enter a valid day", element);
                }
                if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
                    return errorMessage("Please enter a valid 4 digit year between "+minYear+" and "+maxYear, element);
                }
                if (elementValue.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(elementValue, dtCh))==false){
                    return errorMessage("Please enter a valid date", element);
                }
            }
            return true;
        }
        function formatDate(textBoxObj) {
            var elementValue = textBoxObj.value;
            for (i=0; i<elementValue.length; i++){
                if(((i==2)||(i==5))){}
                else {
                    var c = elementValue.charAt(i);
                    if (((c < "0") || (c > "9"))){
                        alert("Only Numbers Are Allowed");
                        textBoxObj.value='';
                        return false;
                    }
                }
            }
            if((elementValue.length==2)||(elementValue.length==5)){
                textBoxObj.value=elementValue+'/';
            }
            return true;
        }
        function isValidDate(element){
            var elementValue = element.value;
            var daysInMonth = DaysArray(12);
            var pos1=elementValue.indexOf(dtCh)
            var pos2=elementValue.indexOf(dtCh,pos1+1)
            var strDay=elementValue.substring(0,pos1)
            var strMonth=elementValue.substring(pos1+1,pos2)
            var strYear=elementValue.substring(pos2+1)
            strYr=strYear
            if (strDay.charAt(0)=="0" && strDay.length>1)
                strDay=strDay.substring(1)
            if (strMonth.charAt(0)=="0" && strMonth.length>1)
                strMonth=strMonth.substring(1)
            for (var i = 1; i <= 3; i++) {
                if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
            }
            month=parseInt(strMonth)
            day=parseInt(strDay)
            year=parseInt(strYr)
            if(elementValue!="") {
                if (pos1==-1 || pos2==-1){
                    return errorMessage("The date format should be : dd/mm/yyyy", element);
                }
                if (strMonth.length<1 || month<1 || month>12){
                    return errorMessage("Please enter a valid month", element);
                }
                if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
                    return errorMessage("Please enter a valid day", element);
                }
                if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
                    return errorMessage("Please enter a valid 4 digit year between "+minYear+" and "+maxYear, element);
                }
                if (elementValue.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(elementValue, dtCh))==false){
                    return errorMessage("Please enter a valid date", element);
                }
            }
            return true;
        }
        function DaysArray(n) {
            for (var i = 1; i <= n; i++) {
                this[i] = 31
                if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
                if (i==2) {this[i] = 29}
            }
            return this
        }
        <!-- Begin Script for progressbar
        var progressEnd = 15; // set to number of progress <span>'s.
        var progressColor = 'blue'; // set to progress bar color
        var progressInterval = 1000; // set to time between updates (milli-seconds)

        var progressAt = progressEnd;
        var progressTimer;

        function progress_clear() {
            for (var i = 1; i <= progressEnd; i++) document.getElementById('progress'+i).style.backgroundColor = 'transparent';
            progressAt = 0;
        }

        function progress_update() {
            document.getElementById("statusmessage").style.display ="";
            progressAt++;
            if (progressAt > progressEnd) progress_clear();
            else document.getElementById('progress'+progressAt).style.backgroundColor = progressColor;
            progressTimer = setTimeout('progress_update()',progressInterval);
        }

        function progress_stop() {
             document.getElementById("statusmessage").style.display ="none";
             clearTimeout(progressTimer);
             progress_clear();
        }
        // End for progressbar-->

         function submitform(){
                var oForm = document.getElementById('accesscarddata');

                var startdate = document.getElementById("startdate").value;
                var enddate = document.getElementById("enddate").value;
                if(startdate == ""){
                    alert("Please select Start Date.");
                    return false;
                }
                if(enddate == ""){
                    alert("Please select End Date.");
                    return false;
                }
                if(Validate(oForm)){
                    progress_update();
                    document.forms["accesscarddata"].submit();
                }
      }
    </script>
</head>

<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0"
    marginheight="0" marginwidth="0" bgcolor="#FFFFFF">
    <form name="accesscarddata" id="accesscarddata"
        action="LeaveReportServlet" method="post"
        enctype="multipart/form-data">

        <table border="0" width="100%" cellspacing="0" cellpadding="0"
            background="images/topbkg.gif">
            <tr>
                <td width="50%" valign="top"><img border="0"
                    src="images/logo.gif" width="145" height="66"></td>
                <td width="50%" valign="top">
                    <p align="right">
                        <img border="0" src="images/topright.gif" width="315" height="66">
                </td>
            </tr>
        </table>
        <table border="0" width="100%" cellspacing="0" cellpadding="0"
            background="img/blackline.gif">
            <tr>
                <td width="100%">
                    <p align="left">
                        <font color="#F0D8B8" face="Arial" size="2"><b>&nbsp;&nbsp;
                                slingemp&nbsp;&nbsp; |&nbsp;&nbsp; slingemp&nbsp;&nbsp;
                                |&nbsp;&nbsp; slingemp&nbsp;&nbsp; |&nbsp;&nbsp;
                                slingemp&nbsp;&nbsp; |&nbsp;&nbsp; slingemp&nbsp;&nbsp;
                                |&nbsp;&nbsp; slingemp&nbsp;&nbsp; |&nbsp;&nbsp; slingemp</b></font>
                </td>
            </tr>
        </table>
        <p align="center" style="margin-left: 20">
            <font face="Arial" color="#000000" size="4">Attendance Process</font>
        </p>
<div id="statusmessage" style="display:none">
        <table align="center" >
            <tr>
                <td>
                    <div style="font-size:8pt;padding:2px;border:solid black 1px">
                        <span id="progress1">&nbsp; &nbsp;</span>
                        <span id="progress2">&nbsp; &nbsp;</span>
                        <span id="progress3">&nbsp; &nbsp;</span>
                        <span id="progress4">&nbsp; &nbsp;</span>
                        <span id="progress5">&nbsp; &nbsp;</span>
                        <span id="progress6">&nbsp; &nbsp;</span>
                        <span id="progress7">&nbsp; &nbsp;</span>
                        <span id="progress8">&nbsp; &nbsp;</span>
                        <span id="progress9">&nbsp; &nbsp;</span>
                        <span id="progress10">&nbsp; &nbsp;</span>
                        <span id="progress11">&nbsp; &nbsp;</span>
                        <span id="progress12">&nbsp; &nbsp;</span>
                        <span id="progress13">&nbsp; &nbsp;</span>
                        <span id="progress14">&nbsp; &nbsp;</span>
                        <span id="progress15">&nbsp; &nbsp;</span>
                    </div>
                </td>
           </tr>
    </table>
</div>
        <p align="left" style="margin-left: 20">
            <font face="Arial" size="2" color="#000000">&nbsp;</font>
        </p>
        <table border="0" width="100%" cellspacing="0" cellpadding="0">
            <tr>
                <td width="25%" align="left">&nbsp;</td>
                <td width="1%" align="left">&nbsp;</td>
                <td width="64%" align="left">
                    <table border="0" width="100%" cellspacing="0" cellpadding="0">
                        <tr class="darkrow">
                            <td width="2%" align="left">*</td>
                            <td width="20%" align="left">Start Date</td>
                            <td width="58%" align="left"><input type="text"
                                name="startdate" id="startdate" maxlength="10"
                                onkeyup="formatDate(this)" onblur="isValidDate(this)" /> <img
                                src="images/calpicker.png" name="image" id="startdate"
                                onclick="scwShow(document.forms[0].startdate,event,'');return false;">
                            </td>
                            <td width="20%" align="left">&nbsp;</td>
                        </tr>
                        <tr class="lightrow">
                            <td width="2%" align="left">*</td>
                            <td width="20%" align="left">End Date</td>
                            <td width="58%" align="left"><input type="text"
                                name="enddate" id="enddate" maxlength="10"
                                onkeyup="formatDate(this)" onblur="isValidDate(this)" /> <img
                                src="images/calpicker.png" name="image" id="startdate"
                                onclick="scwShow(document.forms[0].enddate,event,'');return false;">
                            </td>
                            <td width="20%" align="left">&nbsp;</td>
                        </tr>
                        <tr class="darkrow">
                            <td width="2%" align="left">*</td>
                            <td width="20%" align="left">Select file</td>
                            <td width="58%" align="left"><input type="file"
                                name="myFile" id="myFile" /></td>
                            <td width="20%" align="left">&nbsp;</td>
                        </tr>
                        <tr class="lightrow">
                            <td width="2%" align="left">&nbsp;</td>
                            <td width="20%" align="left">&nbsp;</td>
                            <td width="58%" align="left"><input type="button"
                                value="Process" onclick="submitform()" /></td>
                            <td width="20%" align="left">&nbsp;</td>
                        </tr>
                        <%
                           if(reportMap.size()>0){ %>
                           <script>
                             progress_stop();
                           </script>
                            <tr class="lightrow">
                                <td width="2%" class="title_sub" align="center">S.No</td>
                                <td width="20%" class="title_sub" align="center">EmployeeID</td>
                                <td width="58%" class="title_sub" align="left">EmployeeName</td>
                                <td width="20%" class="title_sub" align="left">Action</td>
                            </tr>
                            <%
                                        Iterator<Map.Entry<String, String>> entries = reportMap.entrySet().iterator();
                                        while (entries.hasNext()) {
                                            Map.Entry<String, String> entry = entries.next();
                                            if (style % 2 == 0) {
                                                 classname = "darkrow";
                                             } else {
                                                 classname = "lightrow";
                                             }
                                            employeeid = entry.getKey();
                                            employeename = entry.getValue();
                                        %>
                            <tr class='<%=classname %>'>
                                <td width="2%"  align="center"><%=sno %></td>
                                <td width="20%" align="center"><%=employeeid %></td>
                                <td width="58%" align="left"><%=employeename %></td>
                                <td width="20%" align="left"><a href="#" alt='<%=employeeid%>' title='<%=employeeid%>'>sendmail</a></td>
                            </tr>
                            <%
                                sno++;
                                style++;

                                        }

                                     }
                                     %>
                    </table>
                </td>
                <td width="10%" align="right">&nbsp;</td>
            </tr>

        </table>
        <p align="left" style="margin-left: 20">
            <font face="Arial" size="2" color="#000000">&nbsp;</font>
        </p>
        <p align="left" style="margin-left: 20">
            <font face="Arial" color="#000000" size="4">&nbsp;</font>
        </p>
        <p align="left" style="margin-left: 20">
            <font face="Arial" size="2" color="#000000">&nbsp;</font>
        </p>
        <p align="left" style="margin-left: 20">
            <font face="Arial" size="2" color="#000000">&nbsp;</font>
        </p>
        <p align="left" style="margin-left: 20">
            <font face="Arial" size="2" color="#000000">&nbsp;</font>
        </p>
        <p align="center" style="margin-left: 20">
            <font face="Arial" color="#000000" size="1">© COPYRIGHT 2012
                ALL RIGHTS RESERVED SLINGMEDIA.COM</font>
        </p>
        <table border="0" width="100%" cellspacing="0" cellpadding="0"
            background="images/botbkg.gif">
            <tr>
                <td width="100%"><img border="0" src="images/botbkg.gif"
                    width="48" height="12"></td>
            </tr>
        </table>
        <div
            style="text-align: center; font-family: Arial, Helvetica, Sans-Serif; font-size: 11px; color: #777;">
            <a style="text-decoration: none; color: #777;"
                href="#">Tutorials</a> | <a
                style="text-decoration: none; color: #777;"
                href="#">Codes</a> | <a
                style="text-decoration: none; color: #777;"
                href="#">Templates</a>
        </div>
    </form>
</body>
</html>
4

3 に答える 3

3

HttpSession.removeAttribute(String name)を使用します。

指定された名前でバインドされたオブジェクトをこのセッションから削除します。セッションに指定された名前でバインドされたオブジェクトがない場合、このメソッドは何もしません。

if (session.getAttribute("leaveMap") != null) {
    reportMap = (Map<String,String>) session.getAttribute("leaveMap");
    session.removeAttribute("leaveMap");
}
于 2012-05-28T12:12:26.030 に答える
2

データをrequestスコープ[リクエスト属性]に配置するか、新しいリクエストを行うときにサーブレットで白地図で上書きします

于 2012-05-28T12:10:09.793 に答える
2

セッションを使用している場合は、データを反復処理するたびに、そのオブジェクトをセッションから削除する必要があります。ただし、リクエストを使用している場合は、リクエストからデータを削除する必要はありません。毎回、新しいリクエストオブジェクトと新しいデータセットも取得します。

于 2012-05-29T05:35:28.267 に答える