如何阻止 jsp 标签显示默认空消息?
How can I stop a jsp tag from showing default null message?
这是 jsp 页面 registration_of_an_user.jsp
<body>
<div id="container">
<form action="User_Controller_Servlet" method="POST">
<input type="hidden" name="command" value="REGISTRATION_OF_AN_USER" />
<table>
<tbody>
<tr>
<td><label>User name</label></td>
<td><input type="text" name="u_name"></td>
</tr>
<tr>
<td><label>User email</label></td>
<td><input type="text" name="u_email"></td>
</tr>
<tr>
<td><label></label></td>
<td><input type="submit" value="Register"></td>
</tr>
</tbody>
</table>
<p><%=request.getAttribute("message")%></p>
</form>
</div>
这是控制器部分。
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
String _command = request.getParameter("command");
switch (_command) {
case "REGISTRATION_OF_AN_USER":
registration_of_an_user_controller_servlet(request, response);
break;
default:
}
} catch (Exception e) {
throw new ServletException(e);
}
}
private void registration_of_an_user_controller_servlet(HttpServletRequest request, HttpServletResponse response)
throws Exception {
String _user_name = request.getParameter("u_name");
String _user_email = request.getParameter("u_email");
User user = new User(_user_name, _user_email);
if (user_dao.email_exist_or_not_dao(_user_email)) {
request.setAttribute("message", "An user with this email already exists.");
request.getRequestDispatcher("/registration_of_an_user.jsp").forward(request, response);
}
user_dao.registration_of_an_user_dao(user);
get_list_of_users_controller_servlet(request, response);
}
只要 registration_of_an_user.jsp 是 运行,它就会在该段落标记的位置显示空消息。如果我能避免此消息显示默认值,那就太好了。我怎样才能做到这一点?我可以从控制器部分执行此操作还是应该为此使用 java 脚本?非常感谢您对此的建议。
只需将您的 <p>..</p>
置于内部状态即可。
<div id="container">
<form action="User_Controller_Servlet" method="POST">
<input type="hidden" name="command" value="REGISTRATION_OF_AN_USER" />
<table>
<tbody>
<tr>
<td><label>User name</label></td>
<td><input type="text" name="u_name"></td>
</tr>
<tr>
<td><label>User email</label></td>
<td><input type="text" name="u_email"></td>
</tr>
<tr>
<td><label></label></td>
<td><input type="submit" value="Register"></td>
</tr>
</tbody>
</table>
<%if(request.getAttribute("message")!=null){ %>
<p><%=request.getAttribute("message")%></p>
<% } %>
</form>
有效请回复
这是 jsp 页面 registration_of_an_user.jsp
<body>
<div id="container">
<form action="User_Controller_Servlet" method="POST">
<input type="hidden" name="command" value="REGISTRATION_OF_AN_USER" />
<table>
<tbody>
<tr>
<td><label>User name</label></td>
<td><input type="text" name="u_name"></td>
</tr>
<tr>
<td><label>User email</label></td>
<td><input type="text" name="u_email"></td>
</tr>
<tr>
<td><label></label></td>
<td><input type="submit" value="Register"></td>
</tr>
</tbody>
</table>
<p><%=request.getAttribute("message")%></p>
</form>
</div>
这是控制器部分。
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
String _command = request.getParameter("command");
switch (_command) {
case "REGISTRATION_OF_AN_USER":
registration_of_an_user_controller_servlet(request, response);
break;
default:
}
} catch (Exception e) {
throw new ServletException(e);
}
}
private void registration_of_an_user_controller_servlet(HttpServletRequest request, HttpServletResponse response)
throws Exception {
String _user_name = request.getParameter("u_name");
String _user_email = request.getParameter("u_email");
User user = new User(_user_name, _user_email);
if (user_dao.email_exist_or_not_dao(_user_email)) {
request.setAttribute("message", "An user with this email already exists.");
request.getRequestDispatcher("/registration_of_an_user.jsp").forward(request, response);
}
user_dao.registration_of_an_user_dao(user);
get_list_of_users_controller_servlet(request, response);
}
只要 registration_of_an_user.jsp 是 运行,它就会在该段落标记的位置显示空消息。如果我能避免此消息显示默认值,那就太好了。我怎样才能做到这一点?我可以从控制器部分执行此操作还是应该为此使用 java 脚本?非常感谢您对此的建议。
只需将您的 <p>..</p>
置于内部状态即可。
<div id="container">
<form action="User_Controller_Servlet" method="POST">
<input type="hidden" name="command" value="REGISTRATION_OF_AN_USER" />
<table>
<tbody>
<tr>
<td><label>User name</label></td>
<td><input type="text" name="u_name"></td>
</tr>
<tr>
<td><label>User email</label></td>
<td><input type="text" name="u_email"></td>
</tr>
<tr>
<td><label></label></td>
<td><input type="submit" value="Register"></td>
</tr>
</tbody>
</table>
<%if(request.getAttribute("message")!=null){ %>
<p><%=request.getAttribute("message")%></p>
<% } %>
</form>
有效请回复