web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application-context.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>
com.jasperreport.test.SetCharacterEncodingFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping></web-app>struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts>
<constant name="struts.i18n.encoding" value="UTF-8"/>
<package name="default" extends="struts-default,jasperreports-default">
<result-types>
<result-type name="jasper" class="org.apache.struts2.views.jasperreports.JasperReportsResult"/>
</result-types>
<action name="jasperTest" class="com.jasperreport.test.JasperReportAction">
<result name="success" type="jasper">
<param name="location">/our_compiled_template.jasper</param>
<param name="dataSource">myList</param>
<param name="format">PDF</param>
</result>
</action>
</package>
</struts>访问:http://localhost:8080/testJR/jasperTest.action报错:HTTP Status 404 - There is no Action mapped for namespace / and action name jasperTest.哪里出问题了?
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application-context.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>
com.jasperreport.test.SetCharacterEncodingFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping></web-app>struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts>
<constant name="struts.i18n.encoding" value="UTF-8"/>
<package name="default" extends="struts-default,jasperreports-default">
<result-types>
<result-type name="jasper" class="org.apache.struts2.views.jasperreports.JasperReportsResult"/>
</result-types>
<action name="jasperTest" class="com.jasperreport.test.JasperReportAction">
<result name="success" type="jasper">
<param name="location">/our_compiled_template.jasper</param>
<param name="dataSource">myList</param>
<param name="format">PDF</param>
</result>
</action>
</package>
</struts>访问:http://localhost:8080/testJR/jasperTest.action报错:HTTP Status 404 - There is no Action mapped for namespace / and action name jasperTest.哪里出问题了?
解决方案 »
- 几天没人解答了,求帮助
- 软件上传下载程序请求设计
- 一道java转码的问题
- ssh整合老是出问题。找错没头绪,谁能说说经验。
- 求毕业设计+论文(基于jsp、java的BBS论坛的设计与实现)
- 新手求教:java下调用命令行的代码!!谢谢!!!
- STRUTS中用超链接到ACTION,为什么ACTION中不执行????急急
- Collection 的方法请高手解决!!!!
- java.lang.NoClassDefFoundError: org/apache/struts/legacy/GenericDataSource
- 请问synchronized 的一些疑惑
- ssh整合时hibernate映射文件出错!
- @hibernate.query 配置问题
这里的配置有问题
代码逻辑问题不应该报404吧,com.jasperreport.test.JasperReportAction代码都还没执行
有什么问题?你是说应该写成<action name="/jasperTest" class="com.jasperreport.test.JasperReportAction">?试了下,还是不行
可以多继承吗?
com.jasperreport.test.JasperReportActionimport java.util.ArrayList;
import java.util.List;import net.sf.jasperreports.engine.JasperCompileManager;import com.opensymphony.xwork2.ActionSupport;public class JasperReportAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = -2597695688476513241L;
/** List to use as our JasperReports dataSource. */
private List<Person> myList; public String execute() throws Exception { // Create some imaginary persons.
Person p1 = new Person(new Long(1), "Patrick", "Lightbuddie");
Person p2 = new Person(new Long(2), "Jason", "Carrora");
Person p3 = new Person(new Long(3), "Alexandru", "Papesco");
Person p4 = new Person(new Long(4), "Jay", "Boss"); // Store people in our dataSource list (normally they would come from a database).
myList = new ArrayList<Person>();
myList.add(p1);
myList.add(p2);
myList.add(p3);
myList.add(p4); // Normally we would provide a pre-compiled .jrxml file
// or check to make sure we don't compile on every request.
try {
JasperCompileManager.compileReportToFile(
"testJR/our_jasper_template.jrxml",
"testJR/our_compiled_template.jasper");
} catch (Exception e) {
e.printStackTrace();
return ERROR;
} return SUCCESS;
} public List<Person> getMyList() {
return myList;
}
}
所有可以直接把struts.xml放在src目录
或者配置myeclipse,指定发布目标目录