This could be a repeat question, I apologize. I have a jsp page in which I have some buttons. Each button has its own servlet to call. I want to know if there is any way I can call these servlets without using form because the user may choose any of the 3 functionalities given. I also need to pass
Tag: servlets
how to convert PrintWriter to String or write to a File?
I am generating dynamic page using JSP, I want to save this dynamically generated complete page in file as archive. In JSP, everything is written to PrintWriter out = response.getWriter(); At the end of page, before sending response to client I want to save this page, either in file or in buffer as string for…
How can I get a Spring bean in a servlet filter?
I have defined a javax.servlet.Filter and I have Java class with Spring annotations. I want to get the bean UsersConnectionRepository in my Filter, so I tried the following: But it always returns null. How can I get a Spring bean in a Filter? Answer Try: Where usersConnectionRepository is a name/id of your be…
How to add filters to servlet without modifying web.xml
I’d like the ability to modify/configure filters in a different way than web.xml. Here is a static configuration of 2 filters. I’d like the ability to have one filter statically configured and allow that filter to load additional filters. I just wanted to know if anyone knows of lib that already h…
Unable to select project for New->Servlet
I’m unable to create a new servlet because I cannot assign it a project. Also the browse buttons do not work, at all, as in they silently fail Am I missing something basic? I’ve been able to create,…
What is the difference between Servlet response methods addHeader and setHeader?
Can I use setHeader to set an new header? Or Do I need to addHeader first, then use setHeader method? Answer The documentation says that you can add multiple values to a particular header using the addHeader method, whereas an initial value would be overwritten if you use the setHeader method. In both cases a…
How to handle exceptions in Java Web Applications?
i would like to handle my exceptions in a way to warning the user about the errors that occured . What i know is something like: This is the best approach ? If not, what would you suggest ? Best regards, Valter Henrique. Answer An exception can be handled in different ways. In this case, it seems that the exc…
httpURLConnection: how long can a post argument be?
I’m currently using something like this: With this I manage to pass some data to my server. What I’m wondering now is how much can be sent this way? I want to be able to send some xml files (100-200 lines long) and would like to know if I can do this? Jason Answer The post body (it’s not usu…
How to check a uploaded file whether it is an image or other file?
In my web application I have an image uploading module. I want to check the uploaded file whether it’s an image file or any other file. I am using Java in server side. The image is read as BufferedImage in java and then I am writing it to disk with ImageIO.write() How shall I check the BufferedImage, wh…
How can I upload files to a server using JSP/Servlet?
How can I upload files to server using JSP/Servlet? I tried this: However, I only get the file name, not the file content. When I add enctype=”multipart/form-data” to the <form>, then request.getParameter() returns null. During research I stumbled upon Apache Common FileUpload. I tried this:…