servlets

Converting GET method url's to logical permanent links

Hi, I have a J2EE application with a web service which goes like http://servername/service?task=getFile&id=25 How can I convert these type of urls to http://servername/service/getFile/25 http://servername/service/getFile/26 etc? Please provide your suggestions. ...

Ordering of values in HttpServletRequest.getParameterValues()

HttpServletRequest.getParameterValues() returns a String[] containing all values of a given HTTP request parameter. Does anyone know if the order of the values in this array is guaranteed by specification to by the same as the order which those values were passed through in the request? For example, if I have the GET query string x=1&x=...

SiteMesh: Changing the content-type of the response

I'm trying to persuade a SiteMesh decorator to change the content-type of the response, but no joy. The content-type always ends up being the same as the decorated JSP, rather than that of the decorator. For example, say I have a JSP with the header <%@ page contentType="application/xhtml+xml" %> I also have a SiteMesh decorator JSP ...

Accessing the implicit objects from a JSP EL function

When defining a function for the JSP expression language, is there a way to specify that the function requires one of the implicit objects (such as pageContext)? I want to define a function ${my:href('a.jpg')} to be implemented by public static String href(String fileName, PageContext pageContext) but I do not want to have to explici...

HttpServletRequest - Quick way to encode url and hidden field paramaters

In my java app I'm preventing XSS attacks. I want to encode URL and hidden field paramaters in the HttpServletRequest objects I have a handle on. How would I go about doing this? ...

HttpServletRequest - SetParameter

I know that I can use HttpServletRequest.getParameter() to get the URL parameter values. Is there an equivalent method with which I can set/replace the value? ...

Can we call getServletContext() inside contextInialized method ?

Dears, Creating servlet that implments contextInializer interface in this code, then accessing file inside contextinialized() using this line InputStream input = getServletContext().getResourceAsStream("/WEB-INF/file.properties")); this exception occurred java.lang.NullPointerException at javax.servlet.GenericSe...

Passing multiple variables from servlet to client

I hope someone can assist me with this. I'm trying to pass an customer id and customer name from a database result using rpc in gwt to the client. I found a way to pass one variable but I can't find a way to pass them both where the id is attached to the name. Can someone post a code example on how to do this. If you need more info let m...

How to connect Derby Database with Servlet?

Hi, I have never connect a database in java before. May I know should I go about accessing a derby database with servlet? I have checked out this: How do I access a database from my servlet or JSP? But I saw comments on the article saying that this is a bad way to connect. Could any one explain or show me the best way to that I should ...

commons fileUpload: specifying an upload directory within Webapplication context

I'd like to know how to specify an upload directory preferably a relative path to a directory under my WEB-CONTENT directory where I'd like to store uploaded files: I get an error when I specify the upload be store as: **File saveFile = new File("/"+fileName);** please refer to code below Error: INFO: Server startup in 497 ms java.io...

Debug servlets with eclipse (running resin)

I am using eclipse (Java EE edition) to write Java servlets and I would like to utilize the debugging functionality. However, I was reading the tutorial to set this up and when I got to the stage the choose a "Server Runtime Environment", I got stuck. I am using Resin, which does not appear to be in the list of available server runtime...

when developing locally, does it make a difference if the context is '/' or '/appname/' ?

when developing locally, does it make a difference if the context is '/' or '/appname/' ? Assuming you will be deploying to http://www.example.com I like it when my local url is: http://localhost:8080/ but just want to know if the url is http://localhost:8080/appname/ if it makes any difference? ...

File reference, what is the correct syntax

I am trying to refer to a location on my computer, however Java is telling me that I have the wrong syntax. Is this line correct? File newlyUploadedFile = new File("D:\\" + fileName); The thing is the file gets uploaded correctly to the location I want it to go to, but I get the error: java.io.IOException: The filename, direct...

java.lang.NullPointerException: No FileItemFactory has been set.

In attempting to implement fileUpload using the streaming API I get an error described below: As I gather from the Streaming API web page that the "traditional FileItemFactory is completely ignored," I'm wondering what I'm doing wrong. So I've defined a basic method as follows: /** * * @param * @return */ public void doPost(HttpSer...

java.lang.OutOfMemoryError: Java heap space

I've the error described below in the trace, when I try upload an 80,193KB FITS file for processing, in order to display select fields. Basically I have a mock web interface that allows a user to select up to 6 FITS files for uploading and processing. I don't get an error when I upload two [different] FITS files, roughly 54,574KB each, ...

Servlet getting invoked twice when the content type is application/pdf

I have a servlet which copies the InputStream to the ServletOutputstream using the Apache IOUtils. The servlet is getting invoked twice. I have tested both on IE and Firefox. Did anybody encounter situation like this? Please let me know if you have any suggestions. ...

Using Java2D and ServletOutputStream not predictable?

We have some code on production which is effectively doing what this code does: http://java.sun.com/products/java-media/2D/reference/faqs/index.html#Q_Can_I_use_Java2D_to_generate_d This works fine, however I have noticed some concerning behaviour. When a servlet is requested and some image data is returned to the browser via a Servl...

How to integrate JSF with custom servlets?

I'm just getting started on JavaServer Faces and it looks very attractive. However I'd like to use my own servlets in the same web application as JSF. This might be really obvious, but what are the best practices for integrating JSF with a "normal" servlets-based application? This would include accessing JSF data from the servlets (read...

Retrieve multiple images from MySQL

How to retrieve multiple blob images from MySQL database in JSP page? ...

What are some thread safe techniques for storing data about a single user's request in a servlet?

If a servlet is not thread safe, then does that mean that all objects created and referenced during the servlet lifecycle are not thread safe? Maybe I'm not quite getting this, but in Web applications you almost always want to account for data stored during the servlet lifecycle that is pertinent to a single user's request. What are some...