servlets

Servlet/JSP URLs when forwarding requests

My web app has a servlet called admin which when navigated to checks if the user is logged in and if the are directs to the the admin section, but if they aren't it directs them to a JSP page with a sign-in form. The name of the JSP doesn't appear in the URL, it stays as /admin. But then when the JSP posts to another servlet to validat...

Working with Eclipse, writing servlets in java...

Another day, another class... I have gotten everything working for my class in which I am using Tomcat and Eclipse to write java servlets. What I would like to know is why eclipse seems to give me problems when I try to edit the servlet-name in the web.xml file. Does eclipse not allow you to edit this file? I know that it automaticall...

java.util.ConcurrentLinkedQueue

I want to use java.util.ConcurrentLinkedQueue as a non-durable queue for a Servlet. Here's the blurb from the javadoc for the class. An unbounded thread-safe queue based on linked nodes. A ConcurrentLinkedQueue is an appropriate choice when many threads will share access to a common collection. This queue does not permit null element...

Rails testing with out-of-process database access?

I'm building a Rails application that requires some models to interact with some necessary Java libraries. To do this, I want to use Rails on on MRI - not JRuby or RBJ. The Java code only needs read access to the database tables managed by the Rails app. One way to do this is to set up a Servlet that reads the Rails app's database table...

Escaping Special Characters Posted to Servlet

I have a jsp containing a form which posts to a servlet, when the servlet receives the parameters from the form the pound sign (£) is preceded with the following character Â. So £ becomes £. What is causing this and how can I get round it? ...

Servlet URL pattern to match a URL that ends with a slash ("/")

I'd like to specify a Servlet URL pattern to match a URL that ends with a slash ("/") and only a slash. I understand that the pattern /example/path/* will match a URL of http://example.com/example/path/ and that this appears to work. However, that same pattern would also match URLs of http://example.com/example/path/a/ ...

How do I separate out query string params from POST data in a java servlet

When you get a doGet or doPost call in a servlet you can use getparameterxxx() to get either the query string or the post data in one easy place. If the call was a GET, you get data from the url/query string. If the call was a POST, you get the post data all parsed out for you. Except as it turns out, if you don't put an 'action' attrib...

Determining which submit button was used?

Is it possible to determine which submit button was used? I have a confirmation form with 2 submit buttons. The first would confirm the order, do some DB tasks, then redirect. The second, which is a Cancel button, will just redirect to the same page, without doing any DB tasks. Is it possible in the servlet, preferably via the reques...

Access Spring beans from a servlet in JBoss

I want to write a simple servlet in JBoss which will call a method on a Spring bean. The purpose is to allow a user to kick off an internal job by hitting a URL. What is the easiest way to get hold of a reference to my Spring bean in the servlet? JBoss web services allow you to inject a WebServiceContext into your service class using a...

How do I correctly decode unicode parameters passed to a servlet

Suppose I have: <a href="http://www.yahoo.com/" target="_yahoo" title="Yahoo!&#8482;" onclick="return gateway(this);">Yahoo!</a> <script type="text/javascript"> function gateway(lnk) { window.open(SERVLET + '?external_link=' + encodeURIComponent(lnk.href) + '&external_target=' + encodeURIComponent(lnk.target) + ...

Load a context/servlet at startup in Tomcat *WITHOUT* changing deployment descriptor (web.xml)

I've got a foo.war file from a third-party vendor. I've defined a context in my Tomcat configuration by creating conf/Catalina/localhost/foo.xml that contains: <Context docBase="/path/to/foo.war" ...> ... </Context> I want Tomcat to load up the foo context at startup. But the WEB-INF/web.xml (deployment descriptor) in the foo.war fi...

Basic question about servlet mapping

Hi, I am new to J2EE and related stuff in general. I am trying to move a particular web application from a Sun One server deployment on to JBoss. The application is filled with a lot of servlets where each one re-directs to another. There are way too many servlets for me to enter a mapping between each of these servlet class to a URL-ma...

init() method in servlet

can we change the name of the init() method of servlet? i mean to say the life should be- xyz()-service()-destroy() instead of init()-service()-destroy() ...

Servlet long processing cancelation when browser closes.

Hi, I have a servlet which processes a request for a long time. It suppose to keep doing stuff in the loop inside doPost and send data through response's out writer. Effectively that continuously appends data in the clients browser . But the problems accures when client just closes the browser. Inspite of the broken connection the respo...

Question about Jboss deployment

Hi All, I am new to Jboss and deployment of web applications etc. I have two different war files deployed on the same Jboss server. Further they also share some classes which read different properties based on the application settings (Let's call a common class as CommonClass.class which is present in App1.war and App2.war; CommonClass ...

How do you use the output of one servlet inside another servlet's init() method?

Here's what I'm trying to do: public void init(ServletConfig config) { // ... URL url = new URL("http://myhost:port/path/to/otherservlet"); // ... do stuff with contents of url } This works fine, but myhost and port are hardcoded and I want to avoid that. I want URL url = new URL("/path/to/otherservlet"); but that's not...

Calling System.exit() in Servlet's destroy() method

This is a follow up to my earlier question. Tomcat 5.0.28 had a bug where the Servlet's destroy() method was not being invoked by the container on a shutdown. This is fixed in Tomcat 5.0.30, but if the Servlet's destroy() method had a System.exit(), it would result in the Tomcat windows service throwing the Error 1053 and refusing to sh...

Is there a way to get a list of all the Spring application contexts running in the JVM?

I would like to be able to get a list of all Spring application contexts from the web applications running in my servlet container. This so so that I can re-initialise the contexts without restarting or reloading my container or webapps. Is this possible? If so, how? Is there anyway to get a list of all the servlet contexts running on a...

Endless loop in a servlet - recovery possible?

Today I fixed a bug in an application that might have lead to an endless loop in a servlet request/response cycle. So just out of curiousity: What happens, if my servlet actually gets trapped in a for(;;) loop? Is it somehow possible to recover? Will tomcat detect this? Can this instance be killed without restarting the server? Or is ...

How a servlet can get the absolute path to a file outside of the servlet?

We have been using System.getProperties("user.dir") to get the location of a properties file. Now that it has been deployed on Tomcat(via servlet), the System call is giving the location as tomcat and not at the location at where the properties file exist. How can we call the the properties file dynamically? Given: Tomcat is not t...