Can someone tell me how to extract the string returned by the Struts action class from an AJAX response? The following is a snippet of code:
JS call :
xmlhttp=new XMLHttpRequest();
xmlhttp.open('POST', 'getMessage.do', false);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send();
alert(xmlhttp.responseText);
Struts.xml
<action name="getMessage" class="SampleAction" method="getMessage"/>
Act
public String getMessage() {
String msg = null;
HttpSession hSession = this.request.getSession(false);
if(null != hSession) {
if(null != hSession.getAttribute("user")) {
User user = (User) hSession.getAttribute("user");
if(null != user.account) {
msg = user.account.getMessage();
}
}
}
return msg;
}
When I print the response text (using a warning), it prints a message with all the HTML information included. the actual message is in bold
reply message
html > head > title > Apache Tomcat/5.0.28 - / > > ! - {font-family: Tahoma, Arial, sans-serif; : , : # 525D76; font-size: 22px;} H2 {font-family: Tahoma, Arial, sans-serif, : , background-color: # 525D76; font-size: 16px;} H3 {font-family: Tahoma, Arial, sans -serif; : , : # 525D76; font-size: 14px;} BODY {font-family: Tahoma, Arial, sans-serif; : ; background-color: white;} B {font- : Tahoma, Arial, sans-serif, : , : # 525D76;} P {font-family: Tahoma, Arial, sans-serif; : ; : ; : 12 ; } A {color: black;} A.name {color: black;} HR {color: # 525D76;} β /style > /head > body > HTTP Status 404 - action com.sample . SampleAction $$ EnhancerByCGLIB $$ 69b4e30e HR size = "1" noshade = "noshade" > p > b > type/b > /p > p > b > u > com.sample.SampleAction $$ EnhancerByCGLIB $$ 69b4e30e Sample messag e/u > /p > p > b > description/b > u > ( , action com.sample.SampleAction $$ EnhancerByCGLIB $$ 69b4e30e ) . /u > /p > HR size = "1" noshade = "noshade" > h3 > Apache Tomcat/5.0.28/h3 > /body > html >