servlets

Accessing post variables using Java Servlets

The title says it all. All I really want is the equivalent of PHP's $_POST[], and after searching the web for an hour, I'm still nowhere closer....

Invalid <url-pattern> servlet mapping in tomcat 6.0

print("<pre><code><servlet> <servlet-name>myservlet</servlet-name> <servlet-class>workflow.WDispatcher</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>myservlet</servlet-name> <url-pattern>*NEXTEVENT*</url-pattern></servlet-mapping></code></pre>"); Above is the snippet form tomcat's w...

Trouble using JRun to Host Java Servlets

I am deploying new versions of java servlets with JRun as the host. I am having difficulty finding good sources for information about JRun and tutorials about how to configure and manage it. After installing JRun and opening the launcher it can't start the admin server that it creates by default...so obviously I'm running into some issu...

Is there a way to access web.xml properties from a Java Bean?

Is there any way in the Servlet API to access properties specified in web.xml (such as initialization parameters) from within a Bean or Factory class that is not associated at all with the web container? For example, I'm writing a Factory class, and I'd like to include some logic within the Factory to check a hierarchy of files and conf...

Tomcat doFilter() invoked with committed response

I have a Tomcat Filter that delegates requests to the a handling object depending on the URL. This is the only filter in the FilterChain. I have an Ajax app that hammers this filter with lots of requests. Recently I noticed an issue where the filter's doFilter method is often called with a committed response as a parameter (Internally, ...

Unit-testing servlets

I have a bunch of servlets running under the Tomcat servlet container. I would like to separate test code from production code, so I considered using a test framework. JUnit is nicely integrated into Eclipse, but I failed to make it run servlets using a running Tomcat server. Could you please recommend a unit testing framework that suppo...

Accessing Tomcat Context Path from Servlet

In my Servlet I would like to access the root of the context so that I can do some JavaScript minifying. It would be possible to do the minify as part of the install process but I would like to do it on Servlet startup to reduce the implementation cost. Does anyone know of a method for getting the context directory so that I can load a...

Write a Servlet that Talks to JMS (ActiveMQ) and OnMessage Update the Site

I am building a site that uses a simple AJAX Servlet to talk JMS (ActiveMQ) and when a message arrives from the topic to update the site. I have Javascript that creates an XMLHttpRequest for data. The Servlet processes the Get Request and sends back JSON. However I have no idea how to connect my Servlet into my ActiveMQ Message Broker. ...

Can a servlet determine if the data posted to it is enctype="multipart/form-data"?

I have a servlet that is used for many different actions, used in the Front Controller pattern. Does anyone know if it is possible to tell if the data posted back to it is enctype="multipart/form-data"? I can't read the request parameters until I decide this, so I can't dispatch the request to the proper controller. Any ideas? ...

Java Servlet 404 errors

What culprits are the most likely to cause a 404 resource not found error when a page in a given .WAR, autocreated by Sun's J2EE deploytool, is trying to load a Servlet in the same .WAR file? Eg: HTTP Status 404 - /MyServlet/MyServlettype Status reportmessage /MyServlet/MyServletdescription The requested resource (/MyServlet/MyServ...

How to make embedded servlet engine instantiate servlets eagerly?

The problem is simple, but I'm struggling a bit already. Server server = new Server(8080); Context context = new Context(server, "/", Context.NO_SESSIONS); context.addServlet(MainPageView.class, "/"); context.addServlet(UserView.class, "/signup"); server.start(); That's a pretty standard piece of code that you can find anywhere in J...

servlet not in root application's servlet context

I have a war file that I have to deploy as root on glassfish. Deploying the application with "/" as its context root happens successfully. But when I try to run that application by http://localhost/, it throws a 503 saying the requested service() is not currently available. The log file server.log has an error saying "javax.servlet.Servl...

How to avoid temporary file creation on server-side when pushing back full HTML content to clients?

In a server-side application running on Tomcat, I am generating full HTML pages (with header) based on random user-requested sites pulled down from the Internet. The client-side application uses asynchronous callbacks for requesting processing of a particular web page. Since processing can take a while, I want to inform the user about pr...

Usable JSP/Servlet Hosting

Has anyone found a usable JSP/Servlet hosting provider? Lunarpages offers JSP as an option, but the server they use (Resin 2.1) is poorly implemented, out of date, cantankerous, and is always running out of memory. There's javaservlethosting.com, but they apparently have a rather negative reputation for poor service. Myjavaserver.com is ...

Measure Total Network Transfer Time from Servlets

How do i measure how long a client has to wait for a request. On the server side it is easy, through a filter for example. But if we want to take into accout the total time including latency and data transfer, it gets diffcult. is it possible to access the underlying socket to see when the request is finished? or is it neccessary to d...

Unit testing a java servlet

I would like to know what would be the best way to do unit testing of a servlet. Testing internal methods is not a problem as long as they don't refer to the servlet context, but what about testing the doGet/doPost methods as well as the internal method that refer to the context or make use of session parameters? Is there a way to do ...

Writing post data from one java servlet to another

I am trying to write a servlet that will send a XML file (xml formatted string) to another servlet via a POST. (Non essential xml generating code replaced with "Hello there") StringBuilder sb= new StringBuilder(); sb.append("Hello there"); URL url = new URL("theservlet's URL"); HttpURLConnection connection = (HttpURLCon...

Creating a java servlet web application

We have to create a web application for a school project and I'm wondering what best practices are when creating a web application using java servlets, beans and jsp. Specifically I'm curious about servlets. Should a single servlet be created with many methods depending on which page is requested (a single controller) or should a servle...

How to choose the max thread count for an HTTP servlet container?

I'm developing a restful Web service that runs as a servlet (using blocking IO) in Jetty. Figuring out the optimal setting for max threads seems hard. Is there a researched formula for deciding the max number of threads from some easily measurable characteristics of the rest of the setup? ...

When do you use a JSP and when a Servlet?

I have an application that sends the customer to another site to handle the payments. The other site, outside of the customer, calls a page on our server to let us know what the status is of the payment. The called page checks the parameters that are given by the payment application and checks to see whether the transaction is known to u...