RTF/ICS generating servlet uses filename of originating page
Hi,
I am writing a program to allow clients to add/change their scheduling information. As part of this, I am including a feature that allows people to download scheduling information in both RTF and ICS (iCal format). I am using a servlet to generate these files, but when the files are generated, they return the filename of the originating jsp. The program as a whole uses JSF, JSP, EJB3, and MySQL.
Also I would like to know if there is a better way of doing what I'm trying to do, since this is going to be deployed to a website and security is somewhat of a concern.
My JSF Bean method:
public String printRichText() {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
String scheduleId = schedule.getId().toString();
RequestDispatcher view = request.getRequestDispatcher("/printRichText?nameStyle=Initials&scheduleId=" + scheduleId);
try {
view.forward(request, response);
context.responseComplete();
} catch (ServletException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
return null;
}Servlet:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class printRichText extends HttpServlet {
ServletOutputStream out;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
out = response.getOutputStream();
clinicLocation = request.getParameter("scheduleId");
response.setContentType("application/rtf");
response.setHeader("Location", "schedule.rtf");
@Override
public String getServletInfo() {
return "Prints out the schedule in a table format";
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}Regards,
Michael S
This may be a problem with your servlet mapping. Check your web.xml file
Similar Messages
-
Generated servlet error - unable to compile class for JSP - using NB5.5/SS9
I am using NB5.5 beta2 and Sun server 9.0 with JSF 1.1 - all is OK when I am creating firts JSF application - welcomeJSF.jsp page is rendered normally - but when I am adding one more jsp with JSP view and so on - then - I am getting errors in both JSF pages - both - in original welcomeJSF and the new invoice.jsp page
here is code for typical error
org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.JasperException: Unable to compile class for JSP
Generated servlet error:
[javac] E:\Sun\AppServer\domains\domain1\generated\jsp\j2ee-modules\ERPSolution\org\apache\jsp\welcomeJSF_jsp.java:99: cannot find symbol
[javac] symbol : method setJspId(java.lang.String)
[javac] location: class com.sun.faces.taglib.jsf_core.ViewTag
[javac] jspxth_f_view_0.setJspId("id7");
[javac] ^
Generated servlet error:
[javac] E:\Sun\AppServer\domains\domain1\generated\jsp\j2ee-modules\ERPSolution\org\apache\jsp\welcomeJSF_jsp.java:144: cannot find symbol
[javac] symbol : method setJspId(java.lang.String)
[javac] location: class com.sun.faces.taglib.html_basic.OutputTextTag
[javac] jspxth_h_outputText_0.setJspId("id17");
[javac] ^
Generated servlet error:
[javac] E:\Sun\AppServer\domains\domain1\generated\jsp\j2ee-modules\ERPSolution\org\apache\jsp\welcomeJSF_jsp.java:145: setValue(java.lang.String) in com.sun.faces.taglib.html_basic.OutputTextTag cannot be applied to (javax.el.ValueExpression)
[javac] jspxth_h_outputText_0.setValue(org.apache.jasper.runtime.PageContextImpl.getValueExpression("Java Server Faces", (PageContext)_jspx_page_context, java.lang.Object.class, null));
[javac] ^
[javac] 3 errors
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:94)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:384)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:461)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:528)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:507)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:495)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:530)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:409)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:317)
javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:414)
com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:455)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:139)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:108)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:266)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:159)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
note The full stack trace of the root cause is available in the Sun Java System Application Server Platform Edition 9.0 logs.
and there is output for another error:
Generated servlet error:
[javac] E:\Sun\AppServer\domains\domain1\generated\jsp\j2ee-modules\ERPSolution\org\apache\jsp\welcomeJSF_jsp.java:144: cannot find symbol
[javac] symbol : method setJspId(java.lang.String)
[javac] location: class com.sun.faces.taglib.html_basic.OutputTextTag
[javac] jspxth_h_outputText_0.setJspId("id17");
[javac] ^
Generated servlet error:
[javac] E:\Sun\AppServer\domains\domain1\generated\jsp\j2ee-modules\ERPSolution\org\apache\jsp\welcomeJSF_jsp.java:145: setValue(java.lang.String) in com.sun.faces.taglib.html_basic.OutputTextTag cannot be applied to (javax.el.ValueExpression)
[javac] jspxth_h_outputText_0.setValue(org.apache.jasper.runtime.PageContextImpl.getValueExpression("Java Server Faces", (PageContext)_jspx_page_context, java.lang.Object.class, null));
[javac] ^
[javac] 3 errors
and here is code of my new invoice.jsp page:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1><h:outputText value="Java Server Faces" /></h1>
<h:inputText value="#{managerBean.currentInvoice.id}"/>
<h:inputText value="#{managerBean.currentInvoice.description}"/>
<h:inputText value="#{managerBean.currentInvoice.total}"/>
<h:commandButton value="new_invoice"
type="submit"
actionListener="#{managerBean.createNewInvoice}"/>
</body>
</f:view>and faces-config.xml file:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config>
<managed-bean>
<managed-bean-name>managerBean</managed-bean-name>
<managed-bean-class>com.brl.ERPSolution.ui.ManagerBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>managerBean was intended to be backing beans which will call the facaed beans of EJB 3.0 entity beans - but at presnet - almost empty methods are declared there:
package com.brl.ERPSolution.ui;
import javax.faces.event.ActionEvent;
import com.brl.solutions.EJB3.*;
* @author Administrator
public class ManagerBean {
protected int currentInvoiceId;
protected Invoices currentInvoice;
protected InvoicesFacade invoicesFacade;
/** Creates a new instance of ManagerBean */
public ManagerBean() {
/* business methods */
public void createNewInvoice(ActionEvent actionEvent)
invoicesFacade.create(this.currentInvoice);
public Invoices getCurrentInvoice()
return this.currentInvoice;
public void setCurrentInvoice(Invoices currentInvoice)
this.currentInvoice=currentInvoice;
}I read in one blog (actually - the only page which was returned by yahoo - so - this should be very rare error!!!) to try to use Sun server's verifier.bat - and - it reported 0 errors and 0 warning. Build was succesfull as well and also - deployment was without errors - but - above mentioned error appeared during the automatic compilation of jsp pages/servlet when newly deployed jsps are first accessed from remote browser.
So - is it possible, please, to receive some advice - what to do further? I feel that my invoice.jsp page can be with errors, - however - the original welcomeJSF.jsp should be working without errors even the erronwous JFS jsp page is added to web application.
Thans for any adice or hint in advance!!!OK - I have made 'clean and build main project' from NB menu and the deployed the resulting *.war and the error messages have disappeared... So - it seems to be bug...
-
JSP compiler obfuscates generated servlet debug line numbers
Here's something that's been baffling me for a couple of days now.
When WebLogic parses a JSP into servlet Java source, and then compiles the Java
source into a class, it seems to perform a further step to obfuscate debug line
numbers in the _jspService method. This converts the debug line numbers from Java
source code line numbers into JSP line numbers.
At first sight, this may appear to be useful- it means that when an exception
is thrown then it references a line number in the original JSP rather than one
in the generated servlet. However, it actually makes life more difficult when
you consider included JSPs.
Suppose you have a file loginresult.jsp, which uses @include to include a header.jsp
and footer.jsp, both of which contain dynamic content. When WebLogic converts
line numbers, it ignores the JSP that the code came from, so this causes a many-to-one
mapping of line numbers. When an error occurs, the exception will tell you the
line number that it came from, but it won't tell you which JSP caused it. The
many-to-one mapping ensures a loss of information- and no way of retrieving the
real line numbers.
This is an even bigger nuisance when trying to debug JSPs- the debugger hops around
in the generated servlet file without giving any clue as to whereabouts it really
is in the code.
My question is: is there any way of switching off this post-processor behaviour?
One obvious way would be to locate the WebLogic class that does this post-processing,
stub it out and run WebLogic with this class higher up in the classpath. But that's
a last resort.
Secondly, would there be any other impact in turning off this behaviour? Do other
parts of WebLogic rely on this?
Thanks in advance,
Kevin.
Actually, this option turns line-number table replacement on and off, for example,
with jsp like this:
test.jsp
<%
throw new Exception();
%>
and weblogic.xml:
<!DOCTYPE weblogic-web-app PUBLIC "-//BEA
Systems, Inc.//DTD Web Application 7.0//EN"
"http://www.bea.com/servers/wls700/dtd/weblogic700-web-jar.dtd">
<weblogic-web-app>
<jsp-descriptor>
<jsp-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</jsp-param>
</jsp-descriptor>
</weblogic-web-app>
the stacktrace looks like this (note line number 2 - this is JSP line number):
java.lang.Exception
at jsp_servlet.__test._jspService(test.jsp:2)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:945)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:332)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:376)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:242)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:5360)
at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:721)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3043)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2468)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:152)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:133)
and with debug option turned off:
<!DOCTYPE weblogic-web-app PUBLIC "-//BEA
Systems, Inc.//DTD Web Application 7.0//EN"
"http://www.bea.com/servers/wls700/dtd/weblogic700-web-jar.dtd">
<weblogic-web-app>
<jsp-descriptor>
<jsp-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</jsp-param>
</jsp-descriptor>
</weblogic-web-app>
exception stacktrace looks like this (note that line number now is from generated .java file):
java.lang.Exception
at jsp_servlet.__test._jspService(__test.java:87)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:945)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:332)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:376)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:242)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:5360)
at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:721)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3043)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2468)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:152)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:133)
Kevin Thomas <[email protected]> wrote:
> But this isn't useful, as you don't know which JSP the line number is referring
> to! (did it come from the main JSP, or one of the files that it included?)
> Turning debug off is not an answer- because that will lose other useful information
> that is useful to the debugger.
> Kevin.
> "Dimitri I. Rakitine" <[email protected]> wrote:
>>Actually, this is useful when you want to debug .jsp's and not generated
>>..java files. Did you try setting 'debug' jsp-param in the weblogic.xml
>>to
>>false? I think it turns class postprocessing on and off.
>>
>>Kevin Thomas <[email protected]> wrote:
>>
>>> Here's something that's been baffling me for a couple of days now.
>>
>>> When WebLogic parses a JSP into servlet Java source, and then compiles
>>the Java
>>> source into a class, it seems to perform a further step to obfuscate
>>debug line
>>> numbers in the _jspService method. This converts the debug line numbers
>>from Java
>>> source code line numbers into JSP line numbers.
>>
>>> At first sight, this may appear to be useful- it means that when an
>>exception
>>> is thrown then it references a line number in the original JSP rather
>>than one
>>> in the generated servlet. However, it actually makes life more difficult
>>when
>>> you consider included JSPs.
>>
>>> Suppose you have a file loginresult.jsp, which uses @include to include
>>a header.jsp
>>> and footer.jsp, both of which contain dynamic content. When WebLogic
>>converts
>>> line numbers, it ignores the JSP that the code came from, so this causes
>>a many-to-one
>>> mapping of line numbers. When an error occurs, the exception will tell
>>you the
>>> line number that it came from, but it won't tell you which JSP caused
>>it. The
>>> many-to-one mapping ensures a loss of information- and no way of retrieving
>>the
>>> real line numbers.
>>
>>> This is an even bigger nuisance when trying to debug JSPs- the debugger
>>hops around
>>> in the generated servlet file without giving any clue as to whereabouts
>>it really
>>> is in the code.
>>
>>> My question is: is there any way of switching off this post-processor
>>behaviour?
>>> One obvious way would be to locate the WebLogic class that does this
>>post-processing,
>>> stub it out and run WebLogic with this class higher up in the classpath.
>>But that's
>>> a last resort.
>>
>>> Secondly, would there be any other impact in turning off this behaviour?
>>Do other
>>> parts of WebLogic rely on this?
>>
>>> Thanks in advance,
>>
>>> Kevin.
>>
>>--
>>Dimitri
>>
Dimitri
-
Mail to File: Use filename from MailBody to store attachement on filesystem
Hi
I have a Mail to File scenario. The mail contains a body and one binary attachment. The goal is to store the binary attachment on the filesystem with a specific filename which should come from the mail body.
So I have to use PayloadSwapBean to have the attachment. But after this I can't access the mail body through a mapping to store the filename from the body content in DynamicConfiguraton (Adapter Specific Message Properties).
How can I transport the filename from the mail body from the mail sender adapter to the file receiver adapter? Is this only possible with an self-written adapter module?
Thx
manuku> In the meantime I found a very easy solution (without adapter module). The solution was to switch the PayloadSwapBean from the MailSenderAdatper to the FileReceiverAdapter. Due to this small change the mail content was as normal payload present for eg. message mapping. So I was able to use the dynamic configuration to generate the dynamic filename.
Hi Tobias,
I should read the requirements more carefully. You wanted the filename from payload, I gave you a solution for reading the attachment name of the mail
Cheers
Stefan -
The song could not be used because the original file couldn't be found
About a week or two ago I loaded up my iTunes to find that most of my music could not be played. Upon clicking on the songs I got the message "The song '__' could not be used because the original file could not be found. Would you like to locate it?" This was weird because none of my music was missing from my computer and it was in the same file location that it has been in all along. I went into the preferences and noticed that the iTunes media file location was different and I changed it back to what it was before. This helped with about half of the files but I still have about 1500 that I will have to "locate" in order to play. This is a solution, but unfortunately it is very time consuming. Does anyone have a solution that could ultimately fix this and save me the time?
Thanks,
Stunray
Message was edited by: Stunray*Adding new items/removing orphans*
Try iTunes Folder Watch or iTunes Library Updater. Folder Watch is much faster on the adding files front, can be set to run in the background and includes a useful exclusion feature, however it’s really slow at removing orphans. iTLU is better for this although doing it manually after looking at a list of proposed removals generated by Folder Watch is probably faster still. iTLU can also be set to update iTunes when you've used 3rd party tools to change tag info.
tt2 -
Generating reports using RWServlet.class(Patch-12)
Sir,
We have configured the Apache Tomcat-3.2.2 to be the servlet engine for generating reports using oracle.reports.rwcgi.RWServlet. Earlier we have been using, Patch-2. We have created many keys(cgicmd.dat) for the different reports that are there with the mostly needed report parameters(including PARAMFORM=YES). We call the report in the browser giving the URL "http://<machine_name>/oraclereports/servlet/oracle.reports.rwcgi.RWServlet?<key_name>". Now, the report page that gets generated is the parameter form. In the HTML source of this page, the form-submitting action is pointing correctly to URL "http://<machine_name>/oraclereports/servlet/oracle.reports.rwcgi.RWServlet.....". The parameter values are entered and the form submitted. The generated report is perfect..
Some days before, Patch-10 was installed. The RWServlet.class that comes along with this was copied to the oracle/reports/rwcgi folder in Tomcat. Now, when the same steps(calling report) as done before were done, the report is not getting generated, giving the output for no page found. The HTML source of the parameter form shows the form-submitting-action URL as "http://<machine_name>/servlet/oracle.reports.rwcgi.RWServlet.." omitting the "oraclereports" that was there earlier.
Now, we have installed Patch-12, copied the new RWServlet.class. For this case also, the same problem is now encountered. Now, have we have to do any additional configuration somewhere? The page that is generated, on giving the URL ""http://<machine_name>/oraclereports/servlet/oracle.reports.rwcgi.RWServlet/showenv?server=Rep60_MACHINENAME" is showing the SCRIPT_NAME as "/servlet/oracle.reports.rwcgi.RWServlet". Is it something to do with this? We tried putting SCRIPT_NAME as a user environment variable, and also by giving SET SCRIPT_NAME=/oraclereports. Still, the problem persists. Doesn't the HttpServletRequest class have some method that returns the SCRIPT_NAME, i.e, the path where the execution is being done? How could different versions of the same class oracle.reports.rwcgi.RWServlet deployed with the same settings on the Tomcat servlet engine behave differently? Please help us on how to solve this problem..
Thank you,
Regards..
RanjithHi,
Is there some way, i.e., by doing some Tomcat setting changes, that the RWServlet of Patch-10/12 can be made to work like RWServlet of Patch-2(with normal settings)? Please help..
Thank you,
Regards..
Ranjith -
Problem running servlet using PJA tools
Hi
I am trying to run the TeksSurveyPie servlet from the PJA Package.But everytime i run it says
Internal error: Unexpected error condition thrown (java.lang.NoClassDefFoundError: TeksSurveyPie (wrong name: com/eteks/servlet/TeksSurveyPie),TeksSurveyPie (wrong name: com/eteks/servlet/TeksSurveyPie)), stack: java.lang.NoClassDefFoundError: TeksSurveyPie (wrong name: com/eteks/servlet/TeksSurveyPie)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:495)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:110)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$1(URLClassLoader.java:217)
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:192)
at java.lang.ClassLoader.loadClass(ClassLoader.java:300)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:290)
at java.lang.ClassLoader.loadClass(ClassLoader.java:256)
at java.lang.ClassLoader.findSystemClass(ClassLoader.java:629)
at com.iplanet.server.http.servlet.NSServletLoader.findClass(NSServletLoader.java:152)
at com.iplanet.server.http.servlet.NSServletLoader.loadClass(NSServletLoader.java:108)
at com.iplanet.server.http.servlet.NSServletEntity.load(NSServletEntity.java:337)
at com.iplanet.server.http.servlet.NSServletEntity.update(NSServletEntity.java:173)
at com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:427)
I am tryin to access the servlet like this
https://avenger/servlet/TeksSurveyPie?survey=Yes
Pls tell me where i am going wrong...????Its preety urgent ....
thanks
prabhuthe servlet is as below for reference .....
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.servlet.ServletConfig;
import javax.servlet.UnavailableException;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Properties;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Frame;
import java.awt.AWTError;
import java.awt.Image;
import java.awt.image.FilteredImageSource;
import Acme.JPM.Encoders.GifEncoder;
import com.eteks.filter.Web216ColorsFilter;
import com.eteks.awt.servlet.PJAServlet;
* This servlet manages in a simple way a dynamic survey and returns the pie of the survey.
* It can be called in either ways :
* <UL><LI><code>.../servlet/com.eteks.servlet.TeksSurveyPie?survey=mySurvey&answer=myAnswer</code>
* adds the answer <code>myAnswer</code> to the survey <code>mySurvey</code>,
* and then returns the pie of the current state of <code>mySurvey</code>.
* <LI><code>.../servlet/com.eteks.servlet.TeksSurveyPie?survey=mySurvey</code>
* simply returns the pie of the current state of <code>mySurvey</code>.</UL>
* <P>To be platform independant, the servlet uses <code>com.eteks.awt.servlet.PJAServlet</code> as super class,
* to have at disposal an image into which graphics operation can be performed.<BR>
* <code>com.eteks.awt.PJAServlet</code> class and depending classes of <code>com.eteks.awt</code> packages
* must be in the servlet engine classpath, and at least one .pjaf font file (Pure Java AWT Font) must exist
* in the user directory or in the directory set in the <code>java.awt.fonts</code> system property,
* if JVM version <= 1.1.<BR>
public class TeksSurveyPie extends PJAServlet
Properties surveysParam = new Properties ();
String fontsDir = ""; // Default value for "java.awt.fonts" .pjaf fonts directory initParameter
String surveysFile = fontsDir + File.separator + "survey.txt"; // Default value for survey file initParameter
// Colors used to fill the pie
final Color colors [] = {Color.blue,
Color.green,
Color.red,
Color.cyan,
Color.magenta,
Color.gray,
Color.yellow,
Color.pink,
Color.orange,
Color.white};
final Color penColor = Color.black;
public void initPJA (ServletConfig config) throws ServletException
// Store the ServletConfig object and log the initialization
super.initPJA (config);
// Retrieves surveys file path
String param = getInitParameter ("surveysFile");
if (param != null)
surveysFile = param;
param = getInitParameter ("fontsDir");
if (param != null)
fontsDir = param;
FileInputStream in = null;
try
in = new FileInputStream (surveysFile);
surveysParam.load (in);
catch (IOException e)
{ } // Empty properties
finally
try
if (in != null)
in.close ();
catch (IOException ex)
public void destroyPJA ()
try
surveysParam.save (new FileOutputStream (surveysFile), "Survey file");
catch (IOException e)
{ } // Properties can't be saved
public String getFontsPath ()
return super.getFontsPath () + File.pathSeparator
+ fontsDir;
public void doPostPJA (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
doGetPJA (request, response);
public void doGetPJA (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
String survey = request.getParameter ("survey"); // Survey name
String answer = request.getParameter ("answer"); // Proposed answer
String paramWidth = request.getParameter ("width");
String paramHeight = request.getParameter ("height");
int width = paramWidth == null ? 200 : Integer.parseInt (paramWidth);
int height = paramHeight == null ? 100 : Integer.parseInt (paramHeight);
// v1.1 : Changed code to enable image creation
// even if PJAToolkit couldn't be loaded by Toolkit.getDefaultToolkit ()
Image image = createImage (width, height);
if (survey == null)
survey = "";
if (answer != null)
String key = survey + "_" + answer;
String value = surveysParam.getProperty (key);
if (value != null)
// If the answer already exists, increase its value
surveysParam.put (key, String.valueOf (Integer.parseInt (value) + 1));
else
String surveyAnswers = surveysParam.getProperty (survey);
// Add this answer to the other ones
if (surveyAnswers == null)
surveysParam.put (survey, answer);
else
surveysParam.put (survey, surveyAnswers + "," + answer);
surveysParam.put (key, "1");
Hashtable answers = new Hashtable ();
Vector sortedAnswers = new Vector ();
synchronized (surveysParam)
String surveyAnswers = surveysParam.getProperty (survey);
if (surveyAnswers != null)
for (StringTokenizer tokens = new StringTokenizer (surveyAnswers, ",");
tokens.hasMoreTokens (); )
String token = tokens.nextToken ();
int answerCount = Integer.parseInt (surveysParam.getProperty (survey + "_" + token));
answers.put (token, new Integer (answerCount));
// Seek the good place to insert this element
int i;
for (i = 0; i < sortedAnswers.size (); i++)
if (answerCount > ((Integer)answers.get (sortedAnswers.elementAt (i))).intValue ())
break;
sortedAnswers.insertElementAt (token, i);
// Compute the pies of the survey
drawSurveyPies (image, answers, sortedAnswers, width, height);
// Send generated image
sendGIFImage (image, response);
* Generates a GIF image on the response stream from image.
public void sendGIFImage (Image image, HttpServletResponse response) throws ServletException, IOException
// Set content type and other response header fields first
response.setContentType("image/gif");
// Then write the data of the response
OutputStream out = response.getOutputStream ();
try
new GifEncoder (image, out).encode ();
catch (IOException e)
// GifEncoder may throw an IOException because "too many colors for a GIF" (> 256)
// were found in the image
// Reduce the number of colors in that case with Web216ColorsFilter basic filter
new GifEncoder (new FilteredImageSource (image.getSource (),
new Web216ColorsFilter ()),
out).encode ();
out.flush ();
private void drawSurveyPies (Image image,
Hashtable answers,
Vector sortedAnswers,
int width,
int height)
Graphics gc = image.getGraphics ();
// Draw a shadow
gc.setColor (penColor);
gc.fillOval (1, 1, height - 3, height - 3);
gc.fillOval (2, 2, height - 3, height - 3);
// Compute the sum of all values
int sum = 0;
for (Enumeration e = answers.elements ();
e.hasMoreElements (); )
sum += ((Integer)e.nextElement ()).intValue ();
for (int accum = 0, i = 0, deltaY = 0; i < sortedAnswers.size (); i++, deltaY += 15)
int answerValue = ((Integer)answers.get (sortedAnswers.elementAt (i))).intValue ();
int startAngle = accum * 360 / sum;
int angle = answerValue * 360 / sum;
// Fill the anwser pie
gc.setColor (colors [i % colors.length]);
gc.fillArc (0, 0, height - 3, height - 3, startAngle, angle);
// Draw a separating line
gc.setColor (penColor);
gc.drawLine ((height - 3) / 2, (height - 3) / 2,
(int)((height - 3) / 2. * (1 + Math.cos (startAngle / 180. * Math.PI)) + 0.5),
(int)((height - 3) / 2. * (1 - Math.sin (startAngle / 180. * Math.PI)) + 0.5));
accum += answerValue;
if (deltaY + 15 < height)
// Add a comment
gc.setColor (colors [i % colors.length]);
gc.fillRect (height + 6, deltaY + 1, 13, 10);
gc.setColor (penColor);
gc.drawRect (height + 5, deltaY, 14, 11);
// Draw is done with default font
gc.drawString (String.valueOf (100 * answerValue / sum) + "% " + (String)sortedAnswers.elementAt (i),
height + 22, deltaY + 9);
gc.drawLine ((height - 3) / 2, (height - 3) / 2, height - 3, (height - 3) / 2);
// Draw a surrounding oval
gc.drawOval (0, 0, height - 3, height - 3);
Thx
prabhu -
Cannot run a servlet using Tomcat. Urgent
I have a webapplication which uses some jsp's and servlets. The jsp pages work fine when I use
http://hostname:8080/MyWebapp/Filename.jsp
However, when I developed a java servlet and put the class file in WEB-INF/classes directory of my web application and tried to access it.
I got a resource not found error.
The strange thing is that when I put the file in the web-inf/classes folder of examples webapplication (which comes with Tomcat) I am able to run the servlet using
http://hostname:8080/examples/servlet/Class file
I am not sure what is wrong.
Can someone help me.
Thanks in advance
Vamsi.It's predictable. The Servlet and JSP specifications mandate that you cannot directly access resources under WEB-INF directory. You have to set up servlet mapping configuration in your web.xml to specify how to access the resources, both Servlet and JSP, there.
When you copied your files in a demo webapp of Tomcat, the web.xml of the demo app already set up the mapping like following for you. So you could use http://hostname:8080/examples/servlet/Class to visit the servlet.
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
The default setting since Tomcat 4.1 turned off servlet invoker in web.xml under conf directory. You can uncomment the above lines in this file to turn it on. Then you are able to visit your servlet without <servlet-mapping> configured using the following syntax,
http://hostname:8080/<your_app_name>/servlet/<your_servlet_name> -
How to modify VC generated app using webdynpro
hi all
I am trying to modify VC generated source using webdynpro, basically trying to find out if it is possible or not.
I complied a sample application using webdynpro compiler in VC and deployed in the portal server, then i downloaded the genrated zip file from portal server, but to find that the structure is not webdynpro compatible.
i would like to know is this the correct approach?or is there any other way if it is possible to do so.
thanks
praveenModifying Visual Composer using webdynpro is generally not something you can do. You can include webdynpro UI elements and components within a Visual Composer model by using eventing. I give an example here for a BI web application UI element and Visual Composer. This can very easily be extended to webdynpro.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5a40f2f7-0c01-0010-d69f-c6317c5165cd -
Some of the songs I have downloaded into i tunes won't play when I select it to do so. The error message I get is "The song can not be used because the original file can not be found. Would you like to locate it?" When I select yes I'm sent to a screen that has my i tunes library listed. When I select the song in question I'm asked if I would like to open the song. When I select this option I get nothing. The songs I have downloaded must be somewhere because they are listed in my i tunes library and on the screen I've been sent to. I can't the songs to play however. This is not true of all of my songs but it is true of quite a few of them. Actually, one song is too many. How do I get my music to play that seems to be locked up somewhere in the computer?
Presuming they're on your computer, right click on them and then follow the prompts to locate hte file on your computer.
-
I'm really dumbfounded on this one and it's driving me bonkers!!!! On some of my music files there is a ! in front of it, if I try to play the song, I get an error message; "The song "_____" could not be used, because the original file could not be found. Would you like to locate it?"
This began to happen when Chuck made playlists2burn on2CD-and then he would delete the playlist; sending all the song files into oblivion. Certain songs have a ! right next to the file name, and as I stated before, i get that error message:
"The song "_____" could not be used, because the original file could not be found. Would you like to locate it?"
So I click on "Locate". No help. I get a menu with folders that say "catroot" and other folders which names I cannot remember, but I scroll PAST the file folders, & it's just a bunch of ".DLL" files.....I don't understand what any of the names of the folders mean...it's frustr8ing-coz this is my 2nd iTouch, my 1st one got stolen & I can't afford2buy my music back at this time & i NEVER before had a single problem with losing song file locations.
Is there anyone out there who has been through this frustrating game of chasing your tail?....<that's how I feel>
If so I would be ever so gr8ful if maybe someone with the knowledge would be so kind as 2 tell me how/where 2 retrieve these songs & how to put everything back where it belongs, I would be 4ever gr8ful !!!
I can't afford 2 replace the songs just like I'm unable 2 buy back my old music from my stolen iTouch....man that was an awesome collection-someday I'll be able 2 afford 2 do that & I would like 2 have all the new music that I paid 4 but cannot find when I got my new iTouch....that would just be wonderful.
I hope someone sees this post that can help me retrieve these files....losing $100.00 of iTunes is a REAL BUMMER!!!!!!
ThanQ SO very much!
[email protected] or [email protected] or [email protected] .
You can also find me on Facebook, my given name is Tiffinie Trimmer, &
that's my Facebook "handle". ThanQ 4 taking the time 2 read all of this!
hope 2 get a reply someday....I'll B checking all my emails & my Facebook, as well
as marking this page in my FAVORITES so I can find it fast! Take Care!!!I was not complete clear.
Since you never changed the settings in the advanced section of iTunes preferecnes, you have to chech that your music is really in the location setted in the folders reported in the advanced section. If not you have 2 ways: reset the position of this folders or in the actual disk organisation or in the pointing on the preferences.
If you press the reset button you just give to itunes its default setting as for the position of the music files: probably this will be a good choice if you have never changed any default preference.
But before I would check the folders and see if the songs are really there
In my iTune I have this, and I believe it is the default.
Users/YOURHOMEFOLDERNAME/Music/iTunes/iTunes Music -
A friend recenlty replaced my hard drive.
When I try to use itunes--I receive this message: "The song could not be used because the original could not be found, would you like to locate it? Next to my songs I see this: "!" Help--Please!!Well what happened is the pathname to the song has changed slightly.
For instance if the song was located say c\:Windows\User\Mary\Music\iTunesFolder
and now it's c:\Windows\User\MaryXray\Music\iTunesFolder
I'm assuming here your music was replaced in the Music folder like on the old hard drive, that iTunesFolder was simply copied over in whole.
So to fix things, you go into the iTunes Folder in your Music Folder and look for a iTunes Music Library .XML file and open it in a Text Program that has "find and replace" ability.
You find the partial pathname of the old drive and you replace ALL instances of it with the new pathname.
so \Windows\User\Mary would be changed to
\Windows\User\MaryXray
Save the file and reopen iTunes. -
Generate report using Word Report Generation VIs error
When I Generate report using Word Report Generation VIs ,the error is generated.
This is my Vi
can somebody tell the error reason?
The attaché is Vi (one is 2011,other is 8.6)
Attachments:
report-8.6.vi 16 KB
report2.vi 33 KB
template.doc 40 KBHi Ben64
Thank you! The problem is solved.
BUT when I use the Word Easy Graph vi ,the result is
I want the Graph (curve),like as:
How Can I do get the picture.
I have other problem. I want to get default name for the new word file.
liang -
Moved iTunes library to an ext hard drive to make space on my int drive... Followed steps from apple. Now I cannot access my music... It says: "File could not be used because the original file cannot be found. Would you like to locate it?"
I moved my iTunes library to my external hard drive some time ago and I followed the directions listed here on the apple support page. It did copy my library and now is on my hard drive... I can open iTunes and use it to sync all of my devices but I would like to play my music... I can see all of my music files but can not play them if I click on an album or song it says the following: "(file name) could not be used because the original file cannot be found. Would you like to locate it?" I click locate but do not know where to go from there? I need a way to access all files and not to hunt down one at a time on my hard drive... I am pretty sure I deleted the original library to make space on my internal drive which was the reason for moving it. I have tried and tried to fix it and do not have a lot of time to do so with a one and two year old at my house who do not like it whenI sit down at my computer. What to do??? Any help is much appreciated!!!See Make a split library portable. Move all of the bits of the library together in the the correct shape and it should work. Or undo exactly what you did and then start over.
If you're a former Windows user don't try merging two folders together that have the same name by dropping one into the same folders as the other, as that goes badly on a Mac.
tt2 -
Please help - this morning I tried updating one of my old ipods for my wife (this ipod hasn't been updated in 2-3 years). I plugged it into my pc, it was recognized and the software updated. I created a new playlist and tied to sync the ipod. This ipod had never been used on this pc/itunes since the pc is only 2 years old. When I tried to sync the ipod it stated that it would have to erase all the old songs on the ipod prior to syncing. I clicked ok and it proceeded to wipe out the old ipod and sync the new playlist (~1000 songs). When the sync was complete there were only 6 songs from the new playlist (all purchased this morning from itunes) on the ipod and to my horror all ~10,000 song on my pc in itunes now have a ! next to them. Only my recent purchases from itunes do not. When I click on a song with the ! I get the error message "the song " " could not be used because the original file could not be found." How do I correct this issue - I am scared to hook my ipads or other ipods to my pc for fear of losing everything?!?!? I spent 100s of hours burning the 10,000 songs from my cd collection and do not want to have to do it again.
Any help is greatly appreciated.This "original file cannot be found" thing happens if the file is no longer where iTunes expects to find it. Possible causes are that you or some third party tool has moved, renamed or deleted the file, or that the drive it lives on has had a change of drive letter. It is also possible that iTunes has changed from expecting the files to be in the pre-iTunes 9 layout to post-iTunes 9 layout,or vice-versa, and so is looking in slightly the wrong place.
Select a track with an exclamation mark, use Ctrl-I to get info, then cancel when asked to try to locate the track. Look on the summary tab for the location that iTunes thinks the file should be. Now take a look around your hard drive(s). Hopefully you can locate the track in question. If a section of your library has simply been moved, or a drive letter has changed, it should be possible to reverse the actions.
Alternatively, as long as you can find a location holding the missing files, then you should be able to use my FindTracks script to reconnect them to iTunes .
tt2
Maybe you are looking for
-
Help needed in SQL Loader-Urgent..!
Hi All, I am having a staging table with 4 columns, I have to insert values in 3 of the columns from a CSV file using SQl Loader( The CSV file has only 3 columns in it) and a default value has to be inserted in to the 4th column.How can I attain this
-
OC4J intermittently not responding to OHS
We deployed a CRM type system into Production over the last few weeks. We are having the usual environmental issues, but nothing we can't handle. We are however experiencing one very unusual type of behaviour. Every so often, even if the system isn't
-
Can anyone help me solve a krypto problem with iterators?
anyone can help me I am desperately trying to write a method takes a target and an array of non-zero values, and returns true if there is a Krypto solution. A krypto solution is one that you are given a set of non-zero int values and an int target. Y
-
Is it possible to OVERLOAD a super-class method in a sub-class?
Hi all, I have a query that Is it possible to OVERLOAD a super-class method in a sub-class? If it is possible, please give me an example. Thanks, Hari
-
Error Builind Blender From AUR
I am trying to build Blender from the AUR using this package: http://aur.archlinux.org/packages.php?ID=13062 I build it once or twice a month usually. I am getting an error this time, and it seems to have something to do with ffmpeg. In file included