I have used the result type stream in my action method which depends on an ajax call. This ajax call is activated on focus out of a textfield on my JSP. The function of this AJAX call is to display an error if the data entered by the user is already present in the backend server. Basically, the server returns a status code that specifies the outcome of the business logic i.e. in my case if my server returns 1016, the data is already present in the server and thus I display an error.
However, I also have to implement exception handling for the code in my action class method. In this case, what actually happens is that the page to which I want to forward on focus out gets jumbled up in the same place as where my error should have displayed and I get a very ugly output on my web page.
I tried everything I could to redirect to another page but nothing seems to work and all I get is 2 pages jumbled into one.
Here is my struts.xml code for the particluar method (as it was earlier):
<action name="useridCheck"
class="com.action.registration.RegistrationAction"
method="isUserIdAvailable">
<result type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
</action>
This is the AJAX method :
request = $.ajax({
url: "ao/useridCheck.action",
method: "POST",
data: { customerLoginId : userid },
dataType: "text"
});
request.done(function( response ) {
if(response!="") {
$('.error-customerId').html('<span class="clearfix"><img src="../images/ao/ico_error_small.png" alt="error message" class="pull-left error-message" /><span class="error-rgt">'+response+'</span></span>');
$('.error-customerId').prev().addClass('error-field');
v = 1;
}
else
{
$('.error-customerId').text('');
$('.error-customerId').prev().removeClass('error-field');
}
//$('#customerLoginId').addClass('error-field');
// $('.error-amount').prev().addClass('error-field');
});
request.fail(function( jqXHR, textStatus ) {
alert( "Request failed: " + textStatus );
});
What do I have to do in struts.xml or AJAX or in my action method so that the page is redirected on focus out?