【发布时间】:2016-10-14 15:27:46
【问题描述】:
大家好,请查看上面的屏幕设计链接。在顶部您可以看到“找不到员工!”这是故意的,是输入未找到的员工 ID 的结果,如下面的 servlet 所示。但是,我想知道如何定位这个?或者有没有更简单的方式向用户输出反馈?如您所见,该消息通过显示在顶部而破坏了我的 CSS。有没有更好的方法来输出这条消息?或者也许定位out.println?
ViewEmployeeInfo.java:
out.println("Employee Not Found!");
RequestDispatcher qs = request.getRequestDispatcher("ViewEmployee.html");
qs.include(request, response);
ViewEmployee.html:
<!DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8">
<link rel = "stylesheet" type = "text/css" href = "main.css">
<link rel = "stylesheet" type = "text/css" href = "sidebar.css">
<title>Update Employee Information</title>
<style>
table { border-collapse: collapse; width: 50%; } th, td { text-align: left; padding: 8px; } tr:nth-child(even){background-color: #f2f2f2}
tr:hover {background-color: #e2f4ff;}
</style>
</head>
<body>
<ul>
<li><a href="PersonalInfoOutput">View Personal Information</a></li>
<li><a href="ExpenseClaim.html">View Expense Claims</a></li>
<li><a href=asdasd>View Payslips</a></li>
<li><a href="changePassAdmin.html" >Change Password</a></li>
<li><a href ="manageEmployee.html" class=active>Maintain Employee Information</a></li>
<li><a href=asdasdasd>Maintain Tax Information</a></li>
<li><a href=asdasd>Maintain Payroll Items</a></li>
<li><a href="TimeSheet.html">Maintain Timesheet</a></li>
<li><a href="EmployeeExpense.html">Maintain Employee Expenses</a></li>
<li><a href=asda>Run Payroll</a></li>
<li><a href=asdasds>Generate Reports</a></li>
</ul>
<div style=margin-left:25%;padding:1px;>
</div>
<div id="container">
<h1>View Employee Information</h1>
<form action ="ViewEmployeeInfo" method = "post">
<table border ="1">
<tr>
<td>Employee ID Search:</td>
<td><input type = "search" name = "employee_id" pattern="[0-9]{4}" title="4 digit number: e.g. 1234" maxlength="4" required> <input type ="submit" value="Search">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
【问题讨论】:
-
为什么还要用servlet来写html
-
@Ramanlfc html 用于显示页面。我正在使用 servlet 与数据库通信以查看员工是否存在。
-
那么,当您显示来自数据库的信息时,您打算如何显示下一页?使用 JSP、Thymeleaf、FreeMarker,还是……?任何具有动态内容的页面都应该使用具有这些技术之一的模板来构建。 “找不到员工!”消息是动态内容,所以这个页面也应该使用模板构建。