Boa tarde a todos, sou iniciante em struts, e após estudar exemplos na internet tentei implementar algo, mas o mesmo acusa o erro “WARNING: Could not find action or result
There is no Action mapped for action name EditorAction. - [unknown location]”
Abaixo a minha jsp onde tem a function gravaTxt que chama essa action:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>Teste Extjs</title>
<link rel="stylesheet" type="text/css" href="/Prototipo/ext-3.2.0/resources/css/ext-all.css" />
<script src="/Prototipo/ext-3.2.0/adapter/ext/ext-base.js"></script>
<script src="/Prototipo/ext-3.2.0/ext-all.js"></script>
<script>
Ext.onReady(function(){
var MeuForm=new Ext.form.FormPanel({
renderTo:document.body,
title:"Editor Web",
//anchor:'100%',
labelWidth:100,
labelAlign:"left",
layout:"form",
padding:10,
border:false,
frame: true,
width:'100%',
height:'100%',
items:[
{
xtype: 'htmleditor',
id:'editorTxt',
//name: 'editorTxt',
// fieldLabel:'Biography',
width: 770,
height:500,
anchor:'97%'
} ,{
layout: 'column',
width: '100%',
border: false,
labelWidth: 10,
items: [{
layout: 'form',
width: '50%',
labelWidth: 10,
items: [{
xtype: 'button',
id : 'salvarTexto',
text: 'Salvar Texto',
minWidth : 150,
listeners:{
click:function(){
gravaTxt();
}
}
}]
},{
layout: 'form',
width: '50%',
labelWidth: 10,
items: [{
xtype: 'button',
id : 'limpar',
text: 'Limpar Texto',
minWidth : 150,
listeners:{
click:function(){
}
}
}]
}]
}
]
});
var tryToDownload = function (url) {
var oIFrm = document.getElementById("IFrameDownload");
oIFrm.src = url;
} ;
var gravaTxt = function(){
var txt = Ext.getCmp('editorTxt').getValue();
if (txt == '') {
Ext.Msg.alert('Atenção', 'Não há texto para ser salvo');
} else {
Ext.DomHelper.useDom = true;
Ext.DomHelper.append(document.body,{tag:'iframe',id:'IFrameDownload'});
tryToDownload('ajax/java/EditorAction!downloadTxt.action?txt=' + txt);
}
java.web.action
};
});
</script>
</head>
<body>
<iframe
id="IFrameDownload" src="" style="visibility:hidden">
</iframe>
</body>
</html>
a configuração do struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="prototipo" namespace="/ajax/java" extends="struts-default">
<action name="EditorAction" class="java.web.action.EditorAction"> </action>
<!-- Add actions here -->
</package>
<!-- Add packages here -->
</struts>
e a classe EditorAction
package java.web.action;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.xwork.UnhandledException;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class EditorAction extends ActionSupport{
public String downloadTxt() throws UnhandledException {
AjaxResponse wresp = null;
try {
AjaxRequest xreq = (AjaxRequest) ActionContext.getContext().get(AjaxRequest.KEY);
String sql = xreq.getHttpRequest().getParameter("txt").toString();
HttpServletResponse response = ServletActionContext.getResponse();
String nomeArquivo = "texto";
response.setHeader("Content-Disposition", "attachment; filename=" + nomeArquivo + ".doc");
ServletOutputStream outputStream = response.getOutputStream();
outputStream.write(sql.getBytes());
outputStream.flush();
outputStream.close();
wresp = AjaxResponse.SUCCESS();
} catch (Exception ex) {
wresp = AjaxResponse.ERROR();
wresp.setMessage(ex.getMessage());
}
return wresp.getResult();
}
}
Bom agradeço a qualquer ajuda…se precisarem de outro arquivo é só pedir que eu posto…