servlets

Correct usage of Stateful Beans with Servlets

We currently have a Stateful bean that is injected into a Servlet. The problem is that sometimes we get a Caused by: javax.ejb.ConcurrentAccessException: SessionBean is executing another request. [session-key: 7d90c02200a81f-752fe1cd-1] when executing a method on the stateful bean. public class NewServlet extends HttpServlet { @EJ...

how to keep multiple Java HttpConnections open to same destination

We are using HttpURLConnection API to invoke a REST API to the same provider often (kind of an aggregation usecase). We want to keep a pool of 5 connections always open to the provider host (always the same IP). What is the proper solution? Here is what we tried: System.setProperty("http.maxConnections", 5); // set globally only once...

Does a RequestDispatcher forward maintain the original request's HTTP method?

I want to intercept a request using the RequestDispatcher, and then I want to forward the request along to another servlet -- something like this: RequestDispatcher dispatcher = request.getRequestDispatcher("/servlet/some.ThirdPartyServlet" + "?" + "param_name=" + "somevalue"); dispatcher.forward(request, response); If the incoming re...

Upload the image with preview

Hi I wanted to upload images(along with other form details) and preview them, using jsp and servlets. I am able to do the uploading part but could not get, how to preview the images in the frontend. I am using YUI to implement it. Actually I am trying to reuse an example which is implemented in PHP. I am attaching my Servlet code here....

authenticating the username ,password by using filters in java (contacting with database)

The following is the piece of java code by using filters that shows the error page at every time if the username and password is also correct. Please help me, I don't have much knowledge on this concept. String sql="select * from reg where username='"+user+"' and pass='"+pwd+"'"; rs=st.executeQuery(sql); if(rs.next()) { chain.doFilt...

How to call sessionDestroyed when a session times out

I am new to JSP. I used the following code in a class that implements HttpSessionListener to get SESSION OUT when the session times out: public void sessionCreated(HttpSessionEvent arg0) { System.out.print("SESSION Created"); } public void sessionDestroyed(HttpSessionEvent arg0) { System.out.print("SESSION...

How can I do username,password validation at server side by contacting with Oracle database

How can I do the username and password authentication(the username and the password is stored in the database then contact with the database to validate if the username and the password is valid or not. If the username and the password is valid then show the next page otherwise show the same login page with error message) ...

Java/JSP HttpServletResponse issue

Hi All, In my java class I am trying to do something like HttpServletResponse.setCharacterEncoding("UTF-8"); but the code fails to compile with the message: Depend attribute is not supported by modern compiler. If I remove this line, code compiles without any issues. Can anyone shed any light on this? Thanks ...

table created using jquery is not accessible from servlet

Based on the help availed from stackoverflow I created the table with hiddenfields to pass the value to servlet, but in servlet I am unable to get the values of the input fields. Here is my jQuery code to create table: $("#linkInstr").click(function() { var arr = new Array(); var cdid = $("#cboinstr option:selected"); var c...

How to control cache in JSP page?

I created a Servlet filter with the following code in doFilter: HttpServletResponse httpResponse = (HttpServletResponse)response; httpResponse.setHeader("Cache-Control","no-cache"); httpResponse.setHeader("Pragma","no-cache"); httpResponse.setDateHeader("Expires", 0); chain.doFilter(request, response); I want to make sure that noth...

How to bind ServletRequest params to domain objects?

I want to bind parameters of a ServletRequest to arbitrary domain objects. Params are available as a map of type Map<String, String[]> // String = key, String[] = values They should be converted and bound to the fields of the target object. Id like to have a method like this: // definition: public void bind(Map<String, String[]>, T...

Java web development, what skills do I need?

I want to learn, at least at a basic level, how to build java web applications (coming from a .net background). Meaning, I would like to be able to build, deploy a simple cms type application from the ground up. What exactly do I need to learn? Tomcat seems to be a good web server for Java. What options are there for the web? I kn...

How to let the servlet container (Tomcat) interrupts/destroys a servlet request?

Dear All,,, I am new in Servlet, I used the following code to read some inputStream, class MyServlet implements Servlet{ void service(ServletRequest req, ServletResponse res){ InputStream inA, inB, inC; //... inA.read(); // May block inB.read(); // May block inC.read(); // May block // ... } } How to let the se...

Is it safe to use java.util.Timer inside servlet ?

Hi all, for many reasons, it is not good practice to use threads inside servlet. java.util.Timer seems like wrapper to threads. so also it is not safe to use it ? if yes, what is the safest way to schedule task in servlet ? thanks,,, ...

Capture generated dynamic content at server side

Is there any way with which I can capture generated dynamic content on the server side and get that file or string object of the same to the servlet. We can generate dynamic content with JSPs, but we dont have access to the generated dynamic content at the server side. As soon as we do the forward container generates the dynamic content...

How to Attach styleSheet.css in tomcat (Servlet)

Hey! I have made a webpage in Servlet and now i want to add a stylesheet.css to it Where should i exactly put the .css file ? like in ROOT of tomcat or some where else and what exact path i have to use?? link href='style.css' rel='stylesheet' type='text/css' Thanks Sundhas ...

accesing value data using request

Hi All, I have form with two buttons having same name but different values ,how to get the value of both the buttons having same name but different value using request ? <form action="controller"> <input class="smallbutton" name="op" value="login" type="submit"/> <input class="smallbutton" name="op" value="SignUp" type="submi...

request.isUserInRole("ADMIN") also returns true for user not in role ADMIN but role USER

Hi, I'm currently trying out the JDBCRealm in Glasshfish v3: I have 2 roles USER and ADMIN. I have a LoginServlet that redirects to a url (say /admin or /user) based on the request.isUserInRole("ADMIN") method. Problem is when a ADMIN is logged in it returns true, so gets redirected to /admin but he can also access the /user. When a U...

A Servlet Container on top of Hadoop?

i'm on the architectural phase of a big project and i've decided to use hbase as my database, and will use map/reduce jobs for my processing so my architecture works totally under hadoop. The thing is i also need to implement some REST, SOAP API's some web pages too so i was thinking is there any servlet container that runs on top of h...

How to clear the screen output of a Java HttpServletResponse

I'm writing to the browser window using servletResponse.getWriter().write(String). But how do I clear the text which was written previously by some other similar write call? ...