如何检查唯一身份用户? [英] How to Check for a Unique User?
问题描述
我有任何应用程序,其中 email_id
是唯一的,每当最终用户输入 email_id
时我通过Ajax发出了一个SQL查询,检查这个电子邮件ID
是否存在。直到这里它的工作正常,但现在我在 email_is
存在时,那么我想在JSP页面上显示这个id已被采用,反之亦然。
I'm having any application in which I have email_id
as unique and whenever an end user enters his email_id
I have fired an SQL query through Ajax which check whether this email id
exists or not. Until here its working fine but now I what that is when email_is
exists then I want to display on the JSP page that This id is already taken and vice-versa.
所以我的问题是如何从struts应用程序获取响应并将其提供给Ajax或JSP页面以及在struts.xml结果标记中写入什么内容?
So my question is how to get the response from struts app and give it to Ajax or JSP page and what to write in "struts.xml" result tag?
这是我对 EmailCheck.action的Ajax调用
:
$("#email").blur(function() {
var EmailV = $("#email").val();
if(EmailV.length > 10){
$('#Loading').show();
$.get("EmailCheck.action", {
Email_Id: EmailV
}, function(response){
$('#Info').fadeOut();
$('#Loading').hide();
setTimeout("finishAjax('Info', '"+escape(response)+"')", 450);
});
return false;
}
});
这是我的 struts.xml
应该在那里是此电子邮件类型检查程序的结果标记?
This is my struts.xml
should there be result tag for this Email type checker?
<action name="EmailCheck" class="org.register.customers.EmailCheckAction" method="EmailCheck">
<result name="input">index.jsp</result>
<result name="success">success.jsp</result>
<result name="error">error.jsp</result>
</action>
这是我的行动代码:
public String EmailCheck() throws Exception{
System.out.println(user.getEmail_Id());
boolean create = Check_Email(user);
// "this is my sql call to check the existence of email"
if (true) {
return "input";
} else {
return ERROR;
}
}
推荐答案
如果如果您调用Ajax操作,则可以返回调度程序
结果。在这种情况下,呈现的JSP片段将作为响应输出。此外,您还可以选择返回流
, json
或无
结果。对于您的情况,我会考虑第一个选项。首先查看此答案,让您熟悉如何返回流
text / html
内容类型的结果。然后在JSP中你应该创建一个目标div来放置响应。
If you call an Ajax action you can return a dispatcher
result. In this case a rendered JSP fragment will output as a response. Also, you have options to return a stream
, json
, or none
results. To your case I will consider the first option. First look at this answer to get you familiar how to return a stream
result with text/html
content type. Then in the JSP you should create a target div where you put the response.
<div id="result"/>
现在修改你的JS以将结果插入div。
now modify your JS to insert result into div.
}, function(response){
$("result").html(response);
这篇关于如何检查唯一身份用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!