servlets

Accessing Spring beans from servlet filters and tags

I can access Spring beans in my Servlets using WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); in the Servlet's init method. I was wondering is there an equivalent of the WebApplicationContext for servlet filters? Also, is it possible to access Spring beans i...

how to catch and throw errors in JSP

I asked a question along similar lines yesterday as well. In that question I was suggested to have a global filter (which I already had). So I have a JSP like below ....code...code ..tags...html...code Object [] res = iBatisDAO.getReport_pging(null,null,0,null); //call to DB ...more code... ...tags...end In the above code I am intent...

How to listen a socket in Tomcat(servlet container)?

I have to let an web application to listen a socket(ServerSocket), and handle the socket stream. But the application is just deployed in Tomcat which is just a servlet container, it doesn't have JCA support. And establishing a server socket in servlet thread is unreasonable. solution 1: The ugly solution is to write a standalone java ...

getContextPath using servlet

Hi, Context path in jboss-web.xml is mentioned as /Test, but my war file name is Test-0.0.1. I need this war file name using HttpServlet. Please tell me the function name. i tried getContextPath(), but it returns Test. Thanks ...

JRun Servlet Error when attepting to use java object

We have a site in ColdFusion which integrates with a credit card provider using java components. When calling a particular function on a java object: <cfset ResponseObject = AgentObject.request(RequestObject, LogObject)> Where ResponseObject, AgentObject and LogObject are java object created like: <cftry> <cfset AgentObject = c...

How to upload files in JSP/Servlet?

How can I parse an uploaded file using Apache Common FileUpload? I tried this: FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = upload.parseRequest(request); // This line is where it died. Unfortunately, the servlet threw an exception without a clear message a...

how to modularize/organize java web application

I am creating a j2ee web appp and I have created the following packages com.cms.controller (to hold servlets) com.cms.business (to hold busines logic) com.cms.dao (to hold data access objects) com.cms.beans (to hold beans) Now i want to write a functionality. So i have written a index.jsp page which has action = /loginConrol...

Making GWT application crawlable by a search engine.

I want to use the #! token to make my GWT application crawlable, as described here: http://code.google.com/web/ajaxcrawling/ There is a GWT sample app available online that uses this, for example: http://gwt.google.com/samples/Showcase/Showcase.html#!CwRadioButton Will serve the following static webpage to the googlebot: http://gwt.goo...

Servlet Profiling

What is the best way to undertake Servlet profiling? In particular I am looking for a solution that can show the execution times of the method calls within the servlet. I am running the Servlet within a Tomcat environment. I have tried VisualVM but it only allows me to see the method calls from the Tomcat thread rather than the Servle...

Is it possible to use jsp variable value to initialize JQUERY variable?

I have some questions which are as follows: How can I use the JSP variable/array in JQUERY code? Here what ever the JQUERY code we have is stored in separate .js file and that file is included in the JSP file. Actually I want to initialize the JQUERY array with the JSP variable. So please guide me to achieve this task. ...

Database connection via Hibernate in servlets

What is the best place in servlet for Hibernate code that returns HibernateSessionFactory ? I saw many examples: ones put db connection in service methods. Others - use smth like HibernateUtil (Singleton) that returns HibernateSessionFactory. I don't know is it safe to use HibernateUtil in multithreaded Servlets ? ...

How to inject dependencies into HttpSessionListener, using Spring?

How to inject dependencies into HttpSessionListener, using Spring and without calls, like context.getBean("foo-bar") ? ...

Is there a way to make a Google Web Toolkit (GWT) Button look like a HTML Hyperlink?

I plan on appending some comments onto a text, to do that, first, I need the concerned text to act like a button for me to launch a popup, which in turn shows the comment. For that to happen, I need to make that concerned text to act like a button in GWT, but due to some aesthetic reasons I don't want it to look like a normal GWT Button,...

In java servlets, how do I tell if the current request is from an include?

From within a servlet, how can I tell if the servlet is being called by a RequestDispatcher("").include, or if it was called normally? ...

stoping doGet/dopost in java servlets ?

Hello everyone, I've been playing with Java Servlets and Ajax a bit, and I've got a situation on which I would really appreciate advice. Let's say I have HTML page with a start and stop buttons, and as a result of clicking start button, overridden doGet (or doPost) method on a servlet is invoked which computes something that takes a l...

servlet connection to DB

Initially, after reading books on the subject, I firmly believed that the algorithm for working with a database from a servlet is as follows: create a connection -> connect to the database -> form a request -> send the request to the database -> get the query results -> process them -> close connection -> OK. Now, with a better unde...

WebLogic job scheduling

Hello, overflowers :) I'm trying to implement a WebLogic job scheduling example, to test my cluster capabilities of fail-over on scheduled tasks (to ensure that these tasks are executed on fail over scenario). With this in mind, I've been following this example and trying to configure everything accordingly. Here are the steps I've don...

Struts and logging HTTP POST request body

I'm trying to log the raw body of HTTP POST requests in our application based on Struts, running on Tomcat 6. I've found one previous post on SO that was somewhat helpful, but the accepted solution doesn't work properly in my case. The problem is, I want to log the POST body only in certain cases, and let Struts parse the parameters from...

Why are there magic attributes exposed in the Servlet spec?

It's always seemed a little at odds with the principles of Java that the Java Servlet Spec (2.5 version here) includes a set of magic attributes containing info about included resources, namely: javax.servlet.include.request_uri javax.servlet.include.context_path javax.servlet.include.servlet_path javax.servlet.include.path_info javax.s...

Using implementation specific classes with standard JAX-RS

I want to use classes from a specific JAX-RS implementation together with the classes defined by Java EE, which are available on an application server. More specifically I want to use Viewable from Jersey but want to use the default Java EE deployment without wrapper servlet. Is it possible? How? Is it a good idea? Or would it be better...