AJAX 応答から Struts アクション クラスによって返された文字列を抽出する方法を教えてください。以下は私のコードスニペットです:
JS コール:
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"/>
アクション
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;
}
応答テキストを (アラートを使用して) 印刷すると、すべての HTML 情報が含まれたメッセージが印刷されました。実際のメッセージは太字で強調表示されています
応答メッセージ
html>head>title>Apache Tomcat/5.0.28 - エラー レポート/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 ステータス 404 - アクション com.sample.SampleAction$$ の結果が定義されていませんEnhancerByCGLIB$$69b4e30e と結果サンプルメッセージHR size="1" noshade="noshade">p>b>type/b> ステータス レポート/p>p>b>メッセージ u>アクション com.sample.SampleAction$$EnhancerByCGLIB$$69b4e30e および結果に対して結果が定義されていませんメッセージの例/u>/p>p>b>説明/b> u>要求されたリソース (アクション com.sample.SampleAction$$EnhancerByCGLIB$$69b4e30e および結果のサンプル メッセージに対して結果が定義されていません) は利用できません。/u> /p>HR size="1" noshade="noshade">h3>Apache Tomcat/5.0.28/h3>/body>html>