0
サーブレットのseminatic ui modalログインフォーム(home.jsp)からユーザー名とパスワードを取得しています。サーブレットは資格情報を確認し、結果をhome.jspに返します。エラーは同じモーダルで表示する必要があります。エラーメッセージは、このモーダルを開くログインボタンを再度クリックすると表示されるモーダルで最初に実行されたときには表示されません。私はこのエラーメッセージを最初に実行します。これを達成する方法を提案してください。以下は完全なコードです。モーダルでログインエラーメッセージを表示できません
FileBug.java(サーブレット)
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
Bugzilla bugzilla=Bugzilla.getBugzillaInstance("username", "pass");
try {
//some code
}catch(Exception e)
{
request.setAttribute("errorMessage",e.getMessage());
RequestDispatcher dispatcher = request.getRequestDispatcher("/home.jsp");
dispatcher.forward(request, response);
}
}
home.jspを
<a class="item agenda-item" id="test">
<span class="side-agenda-item"> <i class="bug icon"></i> File a Bug</span>
<div class="ui modal test">
<form action="FileBug" method="post">
<div class="ui segments">
<br>
<h3 align="center" class="header">Bugzilla Login</h3>
<div class="ui container">
<c:if test="${not empty errorMessage}">
<c:out value="${errorMessage}"/>
</c:if>
</div>
<div class="ui segment">
<div class="ui input">
<input type="text" name="username" placeholder="Bugzilla Username" required>
</div>
</div>
<div class="ui segment">
<div class="ui input">
<input type="password" name="password" placeholder="Bugzilla Password" required>
</div>
</div>
<div class="ui segment">
<br>
<button class="ui blue button" id="login">Login</button>
<br><br>
</div>
</div>
</form>
</div>
</a>
スクリプト: -
<script>
$(function(){
$("#test").click(function(){
$(".test").modal('show');
});
$(".test").modal({
closable: true
});
});
</script>
<style>
div.ui.modal{
width: 20%;
top: 45%;
left: 75%;
}
div.ui.input {
width: 100%;
}
button#login{
margin: -20px -50px;
position:relative;
top:50%;
left:53%;
}
div.ui.input input {
display: block;
margin: 0 auto !important;
float: none;
}
</style>
をhome.jspをアクセスする前にそれを設定する必要があります。しかし、私は唯一すなわち後に提出し、ユーザによって提供されたユーザ名とパスワードを確認した後、エラーメッセージを表示する必要がありますhome.jspにアクセスする前に、どうすれば設定できますか?変更するコードの部分について説明してください。 –
はい...したがって、モーダルからフォームを削除します。ユーザーがフォームを送信すると、サーブレットに詳細が送信され、要求変数がhome.jspに転送されます。 doPostをdoGetに変更して、単にURLに入力することもできます:/ FileBug –