私はJavaEEとAjaxの開発者としては得意ではなく、サーブレットから情報を取得するときに問題が発生します。
これは私のJSファイルです:
$password = document.getElementById("pass").value;
$name = document.getElementById("name").value;
var $hash="";
if ( $password != '') {
$hash = hex_md5($password);
}
$.ajax({
url: 'identification',
type: 'POST',
data:{pass:$hash,name:$name},
dataType: 'html',
timeout: 1000,
success: function(data){
alert(data);
if(data=='no'){
$("#messages").html("Authentication prob ");
}
else if(data=='db'){
$("#messages").html(" DataBase prob ");
}
else
{
$("body").html(data);
//or i want to redirect to new page
//window.location ="/BookListServlet?nom="+$nom;
}
}
});
これは私のサーブレットです:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String name= request.getParameter("name");
String pass=request.getParameter("pass");
if (name.length()==0)
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("no");
out.flush();
out.close();
}
else if (name.equals("admin")&&pass.equals("0cc175b9c0f1b6a831c399e269772661"))
{
if(bookiml.get_connection()!=null)//db is ok
{
getServletContext().getRequestDispatcher("/BookListServlet").forward(request, response);
}
else
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("db");
out.flush();
out.close();
}
}
else
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("no");
out.flush();
out.close();
}
}
私は大きな問題を抱えています:ページをリダイレクトし、サーブレットからHTMLコンテンツを取得する
識別のために送信されたリクエストをこれに転送してbooklistservlet
から、サーブレットからページを取得する必要があります。
このコードが機能しないのはなぜですか?