Hello I´m newbie in Struts2, Ajax i´m trying make a hello world in Struts2+ajax when i push the button in the same page but i see the hello world in a action, Where is the problem? Sorry i´m learning english, thx.
index.jsp
<?xml version="1.0" encoding="UTF-8"?>
<%@taglib uri="/struts-tags" prefix="s" %>
<%@page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@taglib uri="/struts-tags" prefix="s" %>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" >
<head>
<sj:head jqueryui="true"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>DEMO AJAX</title>
<sj:head jqueryui="true"/>
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
// Processing hello button
$('.buttonhello').click(function() {
$.ajax({
type : "POST",
url : '${pageContext.request.contextPath}/index.html',
success : function(response) {
$('.result').html(response);
}
});
});
});
</script>
<s:form action="ajaxTest" theme="xhtml">
<s:submit value="submit" />
</s:form>
</body>
</html>
I know that this part is bad not know what to write
$('.buttonhello').click(function() {
struts.xml
<action name="ajaxTest" class="com.atorresbr.actions.AjaxTest" method="hello">
<result name="success" >index.jsp</result>
</action>
AjaxTest.java (action)
package com.atorresbr.actions;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class AjaxTest extends ActionSupport {
private static final long serialVersionUID = 1L;
public void hello(){
try {
HttpServletResponse response =
ServletActionContext.getResponse();
response.setContentType("text/plain;charset=utf-8");
PrintWriter out = response.getWriter();
out.println("Hello Ajax");
out.flush();
} catch (Exception e){
}
}
}
I have read many tutorials but this use dojo and I have read that is an outdated version. Thankyou very much.