|
Hi All,
I am little bit new to struts framework though I have used tiles in struts application. Now I want to display charts in my application. After searching I found jFreechart library to create charts. (Though it doesn't generate all the charts, like box in web application).
Now I also found some link on how to use jFreechart in struts application. Though the post are not much descriptive, I tried in the same way to incorporate the chart functionality but it is not working......
Can someone please provide the entries to be made in [B]struts.xml[/B], [B]web.xml[/B] to make this functionality work.
Pls find below the different files I am using to run my application.
I have made the changes that I made for graph functionality in bold
[B][I][U]Struts.xml[/U][/I][/B]
[CODE]="1.0"="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="portal" namespace="/portal" extends="struts-default , [B]jfreechart-default[/B]
">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
[B]<result-type name="chart" class="org.apache.struts2.dispatcher.ChartResult">
<param name="height">150</param>
<param name="width">200</param>
</result-type>[/B]
</result-types>
<global-results>
<result name="error">/pages/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.NullPointerException" result="error"/>
<exception-mapping exception="java.lang.NumberFormatException" result="error"/>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings>
<action name="Login" class="graph.Login">
<result name="success">/pages/display.jsp</result>
<result name="error">/pages/login.jsp</result>
<result name="input">/pages/login.jsp</result>
</action>
[B]<action name="Graph" class="graph.Graph">
<result name="success" type="chart">
<param name="value">chart</param>
<param name="type">png</param>
<param name="width">640</param>
<param name="height">480</param>
</result>
<result name="error">/pages/display.jsp</result>
</action>
[/B]
</package>
</struts>[/CODE]
[B][I][U]web.xml[/U][/I][/B]
[CODE]="1.0"="UTF-8"
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>graphFunctionWeb</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter>
<filter-name>Tiles Filter</filter-name>
<filter-class>org.apache.tiles.web.startup.TilesFilter</filter-class>
<init-param>
<param-name>
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
</param-name>
<param-value>
/WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml
</param-value>
</init-param>
</filter>
[B] <filter>
<filter-name>Chart Filter</filter-name>
<filter-class>org.apache.struts2.dispatcher.ChartResult</filter-class>
</filter>[/B]
<filter-mapping>
<filter-name>Chart Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>Tiles Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
[B]<filter-mapping>
<filter-name>Chart Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>[/B]
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>/pages/login.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>tiles</servlet-name>
<servlet-class>org.apache.tiles.servlet.TilesServlet</servlet-class>
<init-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles-defs.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
</web-app>[/CODE]
[B][I][U]Graph.java[/U][/I][/B]
[CODE]package graph;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.StandardXYItemRenderer;
import org.jfree.data.*;
import com.opensymphony.xwork2.ActionSupport;
public class Graph extends ActionSupport {
private JFreeChart chart;
public String execute() throws Exception {
// chart creation logic...
XYSeries dataSeries = new XYSeries("first"); // pass a key for this serie
for (int i = 0; i <= 100; i++) {
dataSeries.add(i, i+100);
}
XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);
ValueAxis xAxis = new NumberAxis("Raw Marks");
ValueAxis yAxis = new NumberAxis("Moderated Marks");
// set my chart variable
chart =
new JFreeChart( "Moderation Function", JFreeChart.DEFAULT_TITLE_FONT,
new XYPlot( xyDataset, xAxis, yAxis, new StandardXYItemRenderer(StandardXYItemRenderer.LINES)),
false);
chart.setBackgroundPaint(java.awt.Color.white);
return SUCCESS;
}
// this method will get called if we specify <param name="value">chart</param>
public JFreeChart getChart() {
return chart;
}
}[/CODE]
After logging I am redirecting to display.jsp
[CODE]<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Graph display</title>
</head>
<body>
hellooooooooooooooooooo
<div align="center">
<center>
<table border = "0" cellpadding = "0" cellspacing = "0" width="400">
<tr>
<td>
<ul>
<li><a href="portal/Graph.action">Login Application </a></li>
</ul>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>[/CODE]
The error I am getting is :
[COLOR="Red"]SEVERE: Exception starting filter Chart Filter
java.lang.ClassCastException: org.apache.struts2.dispatcher.ChartResult cannot be cast to javax.servlet.Filter
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4071)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4725)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Aug 10, 2011 10:08:08 AM org.apache.catalina.core.ApplicationContext log
INFO: TilesDecorationFilter:Initializing filter
Aug 10, 2011 10:08:09 AM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Aug 10, 2011 10:08:09 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/graphFunctionWeb] startup failed due to previous errors
Aug 10, 2011 10:08:09 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: The web application [/graphFunctionWeb] created a ThreadLocal with key of type [com.opensymphony.xwork2.ActionContext.ActionContextThreadLocal] (value [com.opensymphony.xwork2.ActionContext$ActionContextThreadLocal@ce16ad]) and a value of type [com.opensymphony.xwork2.ActionContext] (value [com.opensymphony.xwork2.ActionContext@32bd65]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Aug 10, 2011 10:08:09 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
SEVERE: The web application [/graphFunctionWeb] created a ThreadLocal with key of type [com.opensymphony.xwork2.inject.ContainerImpl$10] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@130633a]) and a value of type [com.opensymphony.xwork2.inject.InternalContext[]] (value [[Lcom.opensymphony.xwork2.inject.InternalContext;@1c286e2]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
Aug 10, 2011 10:08:10 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Aug 10, 2011 10:08:10 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Aug 10, 2011 10:08:10 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/58 config=null
Aug 10, 2011 10:08:10 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2670 ms[/COLOR]
//////////////////////////////////////////////////////////////////////////////////
But the same code runs when I remove the chart functionality from the xml files. please check and provide some input, will appreciate if u will provide the code snippet.
Some links I checked like, [url]http://struts.apache.org/2.1.6/struts2-plugins/struts2-jfreechart-plugin/apidocs/org/apache/struts2/dispatcher/ChartResult.html[/url]
but not much useful.
Regards,
Chandan
|
|
|
|
|
Pls help and provide the way .....
|
|
|
|
|
How to check with Java that a program is installed on Linux or Mac.
In windows I can check registry for a specific entry or to check the existence of program folder.
Thanks.
|
|
|
|
|
This is not really a Java issue, more one of how to get information from the OS. You would probably need to research program installation on each of these platforms. See also the Java Desktop[^] class.
|
|
|
|
|
Pretty sure there is an environmnet variable that specifies the windows version.
That won't exist on OSX
Probably something similar on OSX.
Although there might even be a VM specific value that has such information.
You can use System.getProperties() to list all the env vars for the VM.
|
|
|
|
|
There are three system properties which give you the information:
os.name
os.version
os.arch
The problem is that there is no standard defined list: different JVM implementations can return different values for these properties as long as they are consistent for the same JVM on the same operating system. Not only that, prior to Java 1.6 u14, the Sun hotspot JVM reported Windows 7 as being Windows Vista version 6.1 and then subsequent releases changed to Windows 7 version 6.1, so anyone who relied on this and upgraded from u14 to a later release suddenly found their code was behaving differently after a so-called "minor" upgrade.
So I would treat these system properties with a certain amount of caution. It might be good enough, though, if all you need to know is "it's not Windows".
|
|
|
|
|
At least for the code I create all of those situations would have required that the apps be certified for the target platform anyways.
But one solution presents itself if it is an issue. Use a configurable source which allows one to map os/vm values to application values.
|
|
|
|
|
Also the reason why I prefer to bundle a Java runtime with the app rather than relying on whatever random version of Java happens to be installed on the customer's machine. That makes it more predictable and easier to control.
I think (can't guarantee this, but I believe it to be true) that the os.name for Windows on the hotspot JVM can be relied on to start with "Windows" (although some versions may report Windows XP as being Windows 2000, and some report Windows 7 as being Windows Vista). Last time I used the JRockit JVM (about 3 years ago) that was the same. And as far as I am aware, different flavours of Linux all start with "Linux". So if that's all you need to know, that should probably be OK. I can't think of a reason why you would want to know that you are running on Ubuntu release 10.04 with Linux kernel 2.6.32 but who knows, I'm sure somebody somewhere has had that requirement in the past.
|
|
|
|
|
I want ajax popup controll using login screen,
please help me...
|
|
|
|
|
|
hi there i am trying write a function that checks if a string contains punctuation characters like %,&,!. because i dont want to user enter an invalid name last_name so i want check the string.
|
|
|
|
|
A quick Google search finds this page[^].
Unrequited desire is character building.
|
|
|
|
|
well yes i know this class but i guess there arent any specific functions which they check specific characters. as you see in the link http://cplusplus.com/reference/clibrary/cctype/ there are several functions. but in java i can't check a string contains only alphabetic characters_?
|
|
|
|
|
You can do this using regular expressions. A google search for "java regular expression" will give you some good links.
|
|
|
|
|
thanks mate i will try it then : )
|
|
|
|
|
The Java functions mirror the same functions in C and cover most of what you need.
Unrequited desire is character building.
|
|
|
|
|
quartaela wrote: because i dont want to user enter an invalid name last_name
How exactly did you determine that such characters would be invalid in the name?
Or more specifically is this a business requirement?
And what exactly do you think the business process will be if someones legal names does have one of the characters that you excluded?
|
|
|
|
|
hey sorry for late answer : ). nope this is not a business requirement only a little work. so i mean you can not use "!+^%.." characters in name. for exmaple "Pe&%ter".
|
|
|
|
|
i think we don't have ispunct,isspace methods in java,if you observe JAVA API you may get clarity.If you know exactly please keep sample code in site along related documentation.
|
|
|
|
|
Hello,
How to pass data (like string) from applet to web page client code? that is to value parameter of a label (or asp label).
Is it possible to change the value of <param .../> (member of <applet> tag) from applet?
Is it possible to do it without javascript?
Thanks.
|
|
|
|
|
Hi,
http://www.cafeaulait.org/course/week5/16.html
http://web-design.lovetoknow.com/Javascript_Applet_Communication
http://bytes.com/topic/javascript/answers/89259-novice-question-regarding-passing-parameters-javascript-applet
|
|
|
|
|
No! I need to pass data from applet to a webpage (to html control) and not from page to applet. Or I need to make any change in webpage from applet that can be detected with a script.
So what I need is to make the webpage know when the applet finishes its function operations/work.
|
|
|
|
|
If the applet is signed I believe you can execute a javascript function from within the applet using the showDocument and provide it a link like:
showDocument(new URL("javascript:myCallback()");
|
|
|
|
|
Hi,
http://download.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html
|
|
|
|
|
#
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d9ac0c6, pid=1972, tid=932
#
# Java VM: Java HotSpot(TM) Client VM (10.0-b23 mixed mode, sharing windows-x86)
# Problematic frame:
# V [jvm.dll+0x13c0c6]
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
--------------- T H R E A D ---------------
Current thread (0x02aac800): VMThread [stack: 0x02b90000,0x02be0000] [id=932]
......................and it goes on to give a lot of other data.
How do I interpret it?
|
|
|
|