servlets

Servlet Exception - getOutputStream() has already been called for this response

In my servlet an exeception thrown as org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response help me to resolve this problem thanks in advance ...

Using filters with Grizzly server running a Jersey REST service

I'm trying to use Grizzly to create a server to run a REST service that I've developed using Jersey. I'm creating the Grizzly server using: final String baseUri = "http://localhost:9998/"; final Map<String, String> initParams = new HashMap<String, String>(); initParams.put("com.sun.jersey.config.property.packages", "me.my.rest.package")...

Override velocity view and output an image instead

I have hijacked the normal processing of velocity templates by calling response.getOutputStream in my controller, and I do get an image, but there is an exception "java.lang.IllegalStateException: getOutputStream() has already been called for this response" whenever an image is generated. Is there a way to tell velocity not to parse the ...

Running servlet class from another class

I just got a servlet class working in Eclipse. I was testing it by deploying it using App Engine, and it would prompt me to run as a Web Application. Now I want to run this code from another class. So I made another class and put "TestServlet ts = new TestServlet();" in the main function. When I run it nothing happens. Do I have to ...

File Download Servlet

How should I implement very basic file download servlet? Idea is that with GET request index.jsp?filename=file.txt user could download for example file.txt from file servlet and file servlet would upload that file to user. I can get file, but how should I implement file download? ...

getServletContext().getAttribute() returning null?

When trying to set Context attributes like so: void init() { String testing = new String(); testing = "This is a test"; getServletContext().setAttribute("test", testing); } In one servlet, and getting the attribute like so: String testing = (String) getServletContext().getAttribute("test") In a second servlet, testing i...

How can state be maintained between Java Servlets?

Situation I have a few single-responsibility Servlets that take a request, do their job, respond, and are done -- no state need be maintained in these cases. However, I have I "Plain Old Java Object" that maintains state information based on actions the user has initiated on the client that I would like to make available upon request t...

Concurrent access to Java servlet's service method

Background: I am using hibernate objects for database access. inside my servlet's doGet I have: Account account=getUserAccountHibernateObject(); doWorkOnAccount(account); decreaseAccountBalanceAndSaveToDB(account); Since servlet allows concurrent access, the accountBalance is really messed up sometimes. I have several questions: W...

windows-1252 character 146 is stopping POST data reaching servlet in glassfish v2

An HTTP POST request is made to my servlet. There is a posted form parameter in the http request that my code in the servlet retrieves for further processing named "payload". When the value of the payload includes the windows-1252 character "’" (ascii value 146), HttpServletRequest instance method getParameter("payload") returns null. ...

Javascript calling a java Servlet and return data help.

I don't have much experience with servlets and I've been going around in circles search for an answer to my issue. So it' time to get the experts answers! :) Overview: I need to get Javascript to call my servlet and return data to update the value on a form. I have a java servlet running in Glassfish V2.1 called DBGet, the purpose of ...

Changing default Servlet response

I have a Java Web application that has several servlets with the following mappings. ServletOne -> /one ServletTwo -> /two ServletThree -> /three When I make a request for an action that doesn't exist I get a 403 (Forbidden), ie: /foo. I would like to change that to give a 404 (Not Found). How can I do that? If getting a 404 is def...

How can I know if tomcat is running behind Apache?

In production we run tomcat behind apache, in development bare tomcat. How can I know inside the Servlet class if it is running behind apache or not? ...

How to shutdown a servlet container from within a servlet?

Is there a portable way to request a Servlet container to shutdown gracefully, from within a servlet? By portable I mean a technique that will work on all standard compliant containers (Tomcat, Jetty, Winstone, etc). Note that this is the opposite of the Servlet.destroy() method, which gets called when the container is taking the servl...

comet callback-polling and jetty-cometd implementation

I am using the cometd implementation that comes with the jetty server. I'd like to use the callback-polling transport, but when I try to connect to the comet server from javascript (note that the html page is in another web-server), jetty complains that the servlet does not supports the GET method. Is this an error/bug/whatever of the je...

How to interact with a java servlet running on glassfish with telnet?

I have a servlet hosted in the glassfish server. i want to communicate with it using telnet to understand what is going on behind the scenes when using html form get method. What should i give in the Host field of the HTTP request? Get /WebApplication1/NServlet HTTP/1.1 Host: localhost If i want to send custom properties in the HTTP ...

Configuring servlet to connect to Gmail server

Hi, I'm trying to configure servlet to send a message to Gmail, but I'm getting waiting for reply message down my browser window. Here's the servlet code: import javax.mail.*; import javax.mail.internet.*; import javax.servlet.http.*; import javax.servlet.*; import java.io.*; public class JavaMailServlet extends HttpServlet { pu...

What things should be kept in mind while desigining an HTTP based protocol?

I have heard that http is a nice way to design my own protocol. although i can design a binary protocol, i would prefer to follow the HTTP standard to design my protocol. basically the flow of the application is that with the request the client sends some parameter strings to the server, the server sends the response string to the applic...

Wrap the default servlet but override the default webapp path

I have a folder of static html,imgs,flash content that lives outside of the webapp folder. Right now I'm using a symbolic link to map that folder into my webapp directory. The problem i have is when I undeploy my application it follows the symbolic link and deletes all these files. One of the solutions I'm trying to implement is a spe...

Access file in WebContent folder from a servlet

Hi, I'm trying to generate a PDF document using FOP. The pdf generation code is kept in a servlet and the xsl is in a specific folder in the WebContent folder. How can I access this xsl file by giving a relative path? It works only if I give the complete path in the File object. I need to generate the xml content dynamically. How can...

what is the difference between a portlet and a servlet ?

i am asked to work on portlets and portals. i want to know the difference between a portlet and a servlet ? how/where does a portlet differ(may be functionally) from servlet ? ...