Я вставляю ниже двух файлов JSP. Календарь, который отображается ниже
Применить ваш отпуск здесь Строка не отображается для пользователя, который имеет роль ROLE_MANAGER в качестве роли. Для пользователя ROLE_MANAGER я включил еще один файл JSP. Я попытался удалить include tag и объединить два JSP, но проблема все еще сохраняется.
файл jsp ниже:
welcome.jsp
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript">
$(function(){
$(".calendar").datepicker();
});
</script>
<script type="text/javascript">
function checkDate(){
var sdate = $('#startDate').val();
var edate = $('#endDate').val();
var reason= $('#reason').val();
console.log("the values entered are as follows "+sdate+" "+edate+" "+reason);
if(sdate==""|| edate==""){
alert('please check the date');
return false;
}
if(reason==""){
alert("reason cannot be blank");
return false;
}
var startDate=new Date(sdate);
var endDate=new Date(edate);
if(endDate<startDate){
alert('please check the date');
return false;
}
return true;
}
</script>
</head>
<body style="background-color:powderblue" >
welcome ${pageContext.request.userPrincipal.name} <br><br><br>
Hi ${employee.name}, your employee id is ${employee.empid} <br>
Your email id is ${employee.empEmail} <br>
Your manager id is ${employee.managerid} <br>
Your password is ${employee.password} <br>
You have ${employee.casualLeave} casual leave <br>
You have ${employee.sickLeave} sick leave <br>
You have following roles ${employee.roles}
<br><br>
<sec:authentication property="principal.authorities" var="authorities" />
<c:forEach items="${authorities}" var="authority" varStatus="vs">
<!-- <p>${authority.authority}</p>
<p>${authority}</p>
-->
<c:if test = "${ (authority == 'ROLE_MANAGER') && (hasReords == true)}">
<jsp:include page="manager.jsp"></jsp:include>
</c:if>
</c:forEach>
<br><br>
${dateError}
${leaveError}
<h1>Apply your leave here</h1>
<form:form method="GET" modelAttribute="captureLeave" action="/applyLeave" onsubmit="return checkDate()" >
<label for="datepicker"> start date</label>
<input type="text" name="startDate" placeholder="start date" class="calendar" id="startDate"/> <br>
<label for="datepicker">end date</label>
<input type="text" name="endDate" placeholder="end date" class="calendar" id="endDate"/> <br>
<label > Reason</label>
<input type="text" name="reason" placeholder="Reason" id="reason"/> <br>
Type of leave
<select name="leaveType">
<option value="casual">Casual</option>
<option value="sick">Sick</option>
</select>
<input type="submit" value="submit"/>
</form:form>
<br><br>
<form method="POST" action="/logout">
<input type="submit" value="logout">
<%-- <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> --%>
</form>
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
</body>
</html>
вот менеджер.jsp
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Manager Action</title>
<script>
function myFunction(name, transactionId){
console.log("name passed is "+name+" transaction id is "+transactionId);
alert(name);
$.ajax({
type : 'POST',
url : '/managerAction',
data: {'managerAction': name,
'transactionId': transactionId},
success : function(response) {
alert(response);
},
error : function() {
alert("opps error occured");
}
});
}
</script>
</head>
<body>
<table>
<thead>
<tr>
<th>Employee Name</th>
<th>Leave Applied</th>
<th>Start Date</th>
<th>End Date</th>
<th>Date Applied</th>
<th>Reason for applying leave</th>
<th>Take Action</th>
</tr>
</thead>
<c:forEach items="${employeeRecords}" var="juniors">
<tbody>
<c:forEach items="${juniors.leaveTransactions}" var="leaveRecords">
<tr>
<td>
${ juniors.getName()}
</td>
<td>
${leaveRecords.getLeaveType()}
</td>
<td>
${leaveRecords.getStartDate()}
</td>
<td>
${leaveRecords.getEndDate()}
</td>
<td>
${leaveRecords.getApplyDate()}
</td>
<td>
${leaveRecords.getReason()}
</td>
<td>
<form>
<button type="button" name="Approve" formaction="/managerAction" onclick="myFunction(this.name, ${leaveRecords.getTrans_id()})">Approve</button>
<button type="button" name="Reject" formaction="/managerAction" onclick="myFunction(this.name, ${leaveRecords.getTrans_id()})">Reject</button>
</form>
</td>
</tr>
</c:forEach>
</tbody>
</c:forEach>
</table>
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
</body>
</html>