Ich arbeite derzeit an einem Schulprojekt, das aus der Entwicklung eines Spiels mit Struts2/Jsp besteht. Das Problem, das ich habe, ist, kann ich nicht Daten aus meiner ActionClass zu meinem JSP mit jQuery. Es funktioniert super andersherum und ich habe mehrere Quellen dafür gefunden.Daten von ActionClass zu Jsp Struts2
Hier ist mein minimiert "GameAction.class":
private String playerColor;
private Map<String,Object> applicationMap;
public String execute(){
playerColor = ((Joueur)applicationMap.get("joueur")).getPlayerColor();
return SUCCESS;
}
HINWEIS: alles hat einen Getter/Setter.
game.js:
var $playerColor;
$(window).on('load', function() {
$.ajax({
type : "GET",
url : "gotoGameAction",
data : "playerColor=",
success : function (data) {
$playerColor = data;
var html = "<h2>" + $playerColor.toString() + "</h2>";
$("#playerColor").html(html);
}
})
});
struts.xml:
<package name="default" extends="json-default" namespace="/">
<action name="gotoGameAction" class="actions.logins.GameAction">
<result name="success" type="json">/WEB-INF/views/game.jsp</result>
</action>
</package>
Dieser Ausgang ich auf meinem JSP haben, ist: [object Object].
Ich kann wirklich nicht bekommen, was da los ist kann jemand helfen? Vielen Dank!
Ich habe bereits einen Getter/Setter für playerColor und habe bereits type = "json". Ich habe Daten anstelle von PlayerColor in HTML, aber immer noch das gleiche Problem –
was über 'result' Tag in' struts.xml'. @AymaneELJahrani – Satya
Ich habe versucht, PlayerColor anstelle meines Links zu setzen: Es hat nicht funktioniert –