servlets

servlet: convert an ServletInputStream into a FileInputStream

Hello, i'm writing a servlet that receives a xml file, gives it to another class and gives a html file with some comments back to the client. I'm getting the input-xml with something like: input = request.getInputStream(); but this input is a ServletInputStream and the other class(for the comments) needs a FileInputStream. If i give...

Servlet context serializable attribute persistence

I set a servlet context attribute, which is an object of Serializable class. Does it persist after application server restart as session attributes do? ...

Servlet: cut upload header from the servletinputstream

Hello, I'm writing a servlet that receives an xml file from the client and works with it. My problem is, that in the servletinputstream (which i get with: request.getInputStream()) is some upload information at the beginning and at the end: -----------------------------186292285129788 Content-Disposition: form-data; name="myFile"; fil...

How to use jQuery to call a servlet with multiple non distinct URL params?

I have a servlet that needs a call like http://localhost:8080?a=1&a=3&a=2&b=5. The thing is it has multiple params with the same name like 'a' here. How can I generate such a servlet query. I used this for distinct param names. $.ajax({ url: 'http://localhost:8080', data: {a: 1, b: 2, c: 3}, success: function(response...

GWT: How to return (and handle) an error from multipart form (file) upload

Hello I have and Google Web Toolkit (Multipart) Form which post a file to my servlet. When error condition is happening in servlet I return an error. When everything is OK I return an JSON string. ... response.setContentType("text/html"); response.setCharacterEncoding("UTF8"); response.getWriter().write(out.toString());...

Accessing data from servlet

Hi, I have got a requirement that mysql database can only be accessed from localhost. I have to implement a servlet that would access the database allowing other servers in this system to access data (servlet would work as a proxy). However, this system consists of a remote server which downloads large portions of data executing a state...

Servlet 3.0 support in embedded Jetty 8.0

For my unit-tests I use a simple test-server based on Jetty: package eu.kostia.textanalysis.webservices.jetty; import java.awt.Desktop; import java.net.URI; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.webapp.WebAppContext; public class TestServer { static private final String CONTEXT_PATH = "/webservice"; stati...

Access control for binary files with Java.

Hi All. This is the situation: We have some binary files (PDFs, PPTs, ZIPz, etc.) stored in a server different from where our application is. We need to make them available for the users in our app. But files have extremely sensitive information that can not be read by anyone else but the user that has access to them which means that w...

Problem removing cookie in servlet

I trying to remove a cookie in a servlet with this code Cookie minIdCookie = null; for (Cookie c : req.getCookies()) { if (c.getName().equals("iPlanetDirectoryPro")) { minIdCookie = c; break; } } if (minIdCookie != null) { minIdCookie.setMaxAge(0); minIdCookie.setValue(""); minIdCookie.setPath("/");...

Filter mapping url-pattern that excludes subdirectories

Is there any way to make a filtermapping not include subdirectories? For example. I have .xhtml files in my context root, and I also have a subfolder named "test" with files with the same extension. Is there any may to map a filter to the files in context root and not to the files in the "test" directory? ...

Using init servlet

I am working on a GWT project and naturally need to get some configuration and connect to external resources/objects/systems somewhere. My GWT application interface only has two methods. There are two ways I can setup my application: - Overriding the init in the GWT servlet and required code there and keeping all constructed objects ins...

Redirecting Servlet to Unicode-Domains

I'm having problems with sending redirections to servlet with Unicode-URLs. i.e. consider the following url in Turkish http://türkçeisimtescil.com It works if you paste it into your browser's address bar. However it is translated to http://xn--trkeisimtescil-ijb74a.com by your browser upon your request. Let's say I have fir...

Servlet Session HTTPClient

I got a Servlet A which has a HTTPClient configured in it - declared a GetMethod which calls Servlet B (basically passing the url to the constructor of Servlet B". In Servlet B I am setting some session vars and when the Servlet A gets back the control after the "execute" method but the session vars set in Servlet B are returning as nu...

What is the way to get input

response.setContentType("text/html"); PrintWriter out = response.getWriter(); Connection conn = null; String url = "jdbc:mysql://localhost:3306/"; String dbName = "Employee"; String driver = "com.mysql.jdbc.Driver"; String userName = "root"; String password = "1234"; int Empid =Integer.parseInt(request.getParameter("E...

How to receive 2 or more different Exceptions?

I have written a code to add user into DB. I need to redirect to EmpInfo.jsp, when we receive duplicate entries. I need to use more Exceptions for that and also i want to know how to redirect. response.setContentType("text/html"); PrintWriter out = response.getWriter(); Connection conn = null; String url = "jdbc:mysql:/...

How to deal with private/public pictures of a user created image gallery?

I am working currently on a web project where users can create image galleries and upload pictures. Optionally they can mark pictures as private so that nobody else can look at them. Now i am not sure how to properly implement the protection mechanism. Of course i have some ideas but none of them seems to be optimal. Here is one of my i...

Returning XML from query result in servlet

Hi, I'm trying to return an XML file based on my query results. I'm very new to this so I'm not really sure where I'm going wrong. Is this a realistic way to go about doing this or is there something simpler? Right now I'm getting these exceptions: Error performing query: javax.servlet.ServletException: org.xml.sax.SAXParseException: Co...

How to configure Tomcat 6.0 with MySQL

Can one explain little more about how to configure Tomcat with MySQL? Where to place mysql-connector-java-5.1.13-bin in Tomcat directory? Should I place it under Tomcat 6.0\webapps\myapp\WEB-INF\lib? Do I need to confirgure context.xml or server.xml files? Should I write web.xml file and need to place under Tomcat 6.0\webapps\myapp\WEB...

File class object doesn't delete files when running in a server java

I've been working on my final programming class project, and I am stuck right now, I have to create an inventary for a company. I use textpad to write the code and the icarnegie workbench, to put the classes on it and run it, so the thing is that i have this servlet and from there I call the class called Delete, this class has various me...

Is there a cross-platform way for accessing the JSP servlet?

In Tomcat, we can configure the Web app to treat non JSP files as JSP using the JSP servlet: <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>/scripts/my.js</url-pattern> </servlet-mapping> Is there a cross-platform way to map resources to the JSP servlet? UPDATE: While there's not a cross-platform way availa...