从java servlet输出时如何定位out.println()?

时间:2016-06-14 04:12:06

标签: java html css servlets

enter image description here

大家好,请看一下上面的屏幕设计链接。在顶部你可以看到它说'#34;员工未找到!"这是故意完成的,是输入未找到的员工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>

2 个答案:

答案 0 :(得分:0)

您可以通过在

中添加标记来修改CSS
out.println("<div id="info">Employee Not Found!</div>");

答案 1 :(得分:0)

使用以下out声明

out.println("<span class='messageBox'>Employee Not Found!</span>"); 

使用类<style>...</style>head标记的messageBox内添加css样式,如下所示:

.messageBox {
    color: red;
    margin: 10px;
    padding: 10px;
    font-size: 22px; 
}

根据您的要求更改css !!!!