Can anyone please tell me how to extract a String returned by Struts action class from AJAX reponse? Below is my code snippet:
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
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(); //Sample message
}
}
}
return msg;
}
When I print the response text (using alert), it printed message with all HTML information included. actual message is highlighted in bold
response message
html>head>title>Apache Tomcat/5.0.28 - Error report/title>style>!-- {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}-->/style> /head>body>>HTTP Status 404 - No result defined for action com.sample.SampleAction$$EnhancerByCGLIB$$69b4e30e and result Sample messageHR size="1" noshade="noshade">p>b>type/b> Status report/p>p>b>message u>No result defined for action com.sample.SampleAction$$EnhancerByCGLIB$$69b4e30e and result Sample message/u>/p>p>b>description/b> u>The requested resource (No result defined for action com.sample.SampleAction$$EnhancerByCGLIB$$69b4e30e and result Sample message) is not available./u>/p>HR size="1" noshade="noshade">h3>Apache Tomcat/5.0.28/h3>/body>html>