As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [servlets]

Servlet is a Java application programming interface (API) running on the server machine which can intercept on the requests made by the client and can generate/send a response accordingly.

Filter by
Sorted by
Tagged with
3 votes
1 answer
105 views

synchronized access to HttpSession attribute vs static ConcurrentMap with HttpSessionListener

As a part of library implementing websocket Guice scopes I need to maintain an object related to each HttpSession called ...
morgwai's user avatar
  • 151
0 votes
1 answer
54 views

A Java EE7 web application for counting views in a static HTML page - follow-up

(See the initial and previous version.) This time, I have incorporated all the good points made by mtj. See what I have: ...
coderodde's user avatar
  • 26.7k
0 votes
1 answer
72 views

A Java EE7 web application for counting views in a static HTML page

I have this blog lurking around in the web. It's just static HTML, but I was interested to keep track of all the views on that blog. Finally, I end up with the following web application: (The Java ...
coderodde's user avatar
  • 26.7k
3 votes
1 answer
223 views

Correct synchronization of reads and writes to ConcurrentHashMap and ConcurrentLinkedQueue

I am writing a web application (Servlets, JDBC, no Spring - for learning purposes) that accepts orders from customers, while registered couriers can choose which one of these orders they want to ...
Mike's user avatar
  • 31
1 vote
1 answer
42 views

any better way than using old servlet api for downloads

I am wondering if the following code can be modified to be used with latest version of spring APIs? The following code works fine. However, I wanted to know if servlet APIs can be avoided which i have ...
Tan's user avatar
  • 243
3 votes
1 answer
169 views

Servlet to let a user download a file

Is the code below an efficient way to get the zip file from the server? The code works fine but I'm wondering if I should throw some exceptions for the following conditions: ...
Tan's user avatar
  • 243
7 votes
3 answers
254 views

Java Servlet & JSP simple login

I am currently learning Java Servlets and JSP at university. As a little practice I created a project where I want to be able to login into a protected area. Now, I got it working by using a ...
Moglash's user avatar
  • 568
0 votes
2 answers
681 views

Servlet filter which detects if the authenticated user is a service account

My concern with this code is that I am forcing execution repeatedly through the same pathway for the sake of a readability that I'm not convinced by. It's a servlet filter which detects if the ...
Adam's user avatar
  • 139
2 votes
1 answer
167 views

Implementation of login and registration functions in servlet filter

I'm a newbie in servlet API. I have a test task to create a very simple web app with one home page and an authorization form. The requirement is to use filter somewhere in my app. Given that it's a ...
LexSav's user avatar
  • 123
2 votes
1 answer
2k views

Servlet doPost method that handles multiple actions

I'm interested in reducing the repetition in the doPost() method of my servlet. Specifically, I don't like the loop and error handling repetition. Any other refactoring advice will also be helpful. ...
Cohaven's user avatar
  • 23
3 votes
1 answer
66 views

Two java classes with different annotation values only [closed]

Consider two classes: First ...
wscourge's user avatar
  • 133
1 vote
1 answer
1k views

Simple login with jsp

I made a simple login page with Java EE, jsp, servlet, tomcat and jdbc. It does following: login user register user after login it creates token for the session so ya can be directed from start page ...
wBacz's user avatar
  • 123
2 votes
1 answer
5k views

Server side validation for reCAPTCHA V2 or Invisible reCAPTCHA with Java (Servlet)

The main reason for this post is that I spent quite a lot of time searching the easiest way to validate recaptcha V2. So I'm going to share my knowledge to avoid further time wastage of developers. I'...
Roshana Pitigala's user avatar
-1 votes
2 answers
102 views

Practicing Java servlets, MySQL and JSON - follow-up

(See the previous iteration.) What's new I have incorporated all the points of Dmytro Maslenko's answer. My code seems a little bit tidier. Code AddPersonController.java ...
coderodde's user avatar
  • 26.7k
1 vote
1 answer
862 views

Practicing Java servlets, MySQL and JSON

(See the next iteration.) Introduction This is my attempt at a simplistic web application just for the sake of practice. I have three main servlets: ...
coderodde's user avatar
  • 26.7k
3 votes
3 answers
97 views

Shell script to rebuild a Java webapp

I am asking for an experienced person to review my basic shell script. I do not write them at work, but I am a software developer. I am using this for my personal project that I am working on. Later, ...
TerNovi's user avatar
  • 131
3 votes
0 answers
49 views

oEmbed provider servlet to handle four media types

I would like to add oEmbed tags to my site (I'm the oEmbed api provider). My api should respond the results based on the file type. oEmbed Types has Photo Video Link Rich My response to photo ...
Tom Taylor's user avatar
4 votes
1 answer
95 views

Authenticating and redirecting six specific users

In a project I have a few long switch statements which seem ugly to me. Please suggest how to refactor the following code. ...
miki's user avatar
  • 101
2 votes
0 answers
4k views

Create HTML table in a Java Servlet

Using a java servlet, I've been doing the same approach to building or updating HTML. I create the basic table on the HTML page, then call for the body from the servlet with ajax. As an example: ...
Bob Stout's user avatar
  • 341
4 votes
2 answers
132 views

Filter request code handler

I use the following code which works OK, the code is filtering requests and in case there are too many requests it sends some logs/errors since I'm very new to Java my question if there is a better ...
Jenny M's user avatar
  • 281
2 votes
2 answers
709 views

Logging all API call traffic in Java servlets

We have a few servlets like the one below, taking JSON request and produce JSON response. And the requirement is to log all API call traffic. ...
user2001850's user avatar
1 vote
0 answers
301 views

Sending JSON from a checkbox form

I coded this, which is working but I think there is a better way to do this.. I have a form where the user can check from checkboxes. For each checkbox I have multiple info that I want to send to my ...
yaylitzis's user avatar
  • 111
5 votes
2 answers
2k views

Thread Safe Servlet

I am working on a JSP MVC web application. I am confused about Thread-Safe Servlet concept. Following is my code, please tell me is it thread safe or not. Also, tell me the reason that why it is ...
Waleed Khan's user avatar
5 votes
1 answer
2k views

Java login system using JSP and servlets

The system is pretty simple. Here is how the database looks: ...
Planet_Earth's user avatar
4 votes
1 answer
50 views

Memory mapped classpath HttpServlet

I have a single page application where the resources sit on the classpath. Any request for a resource that doesn't exist should redirect to the index.html page. ...
Cheetah's user avatar
  • 171
5 votes
3 answers
87 views

UrlRouter which uses regular expressions to find out what to do

I have created UrlRouter. It should call appropriate controllers methods with extracted values as a parameters. It works fine, but my boss told me that I should ...
Iaroslav Karandashev's user avatar
6 votes
2 answers
1k views

Servlet file uploader

I think this code looks ugly, especially with the multiple try-catch blocks, but I don't know how to rewrite it: ...
gstackoverflow's user avatar
6 votes
1 answer
106 views

Creating an in-memory ViewCounter that commits to database every 10 minutes

This singleton is responsible for counting every pageview (called Routes in our case) we get by id, until the timer runs out and commits the results to the database in one query. Then the counter gets ...
Thermometer's user avatar
1 vote
1 answer
196 views

Web application for recording blog comments

I am working on some coursework for a simple Java EE web application that records blog comments. On the add comment page there are two fields: name and ...
NRKirby's user avatar
  • 225
9 votes
3 answers
17k views

Sending a file in servlet response, using a class inside a method

I am processing file inside my method - basically preparing it for the download. But I decided to split actions for setting headers and reading bytes. As Java does not support method declaration ...
lapots's user avatar
  • 337
4 votes
1 answer
11k views

Filter to block duplicate POST submission on server side

I am working on a JSF 1.1 webapp. Lots of POST request take some time and users have the bad habit of clicking again when it takes too long. I am planning to target all the long running processes and ...
Aldian's user avatar
  • 214
3 votes
1 answer
395 views

Servlet responses to upload/download requests

My task is to write a program to store files in object store. One of the subtasks requires to send json or xml format response to the file uploader/downloader as requested by client. The following ...
gkiko's user avatar
  • 131
3 votes
0 answers
3k views

Authorization token from servlet filter stores user name

I'm having some difficulty with servlet and filter lifecycles. The intention here is to use the front controller pattern with a simple login; authentication is accomplished with the filter. Am I ...
Thufir's user avatar
  • 379
2 votes
1 answer
361 views

Open source Pastebin tool made in JSP and servlet

I'm a student and still studying. I just made my own Pastebin tool to generate source code. I've also contributed this project as an open source. You could see this project from here. If you wish to ...
user3090104's user avatar
4 votes
0 answers
626 views

Exception logger for servlets and JSPs

I hate using unnecessary catch blocks and I like to see my code look beautiful. In most of the cases in my project, which is a web application, I can't declare many ...
phoenix's user avatar
  • 277
6 votes
1 answer
127 views

Entering information about a business and finding matches

I'm writing a Java Servlet application where the users must enter information about a business. I'd like to prevent as many duplicate entries in the MySQL database as possible and I'd appreciate ...
Bob Stout's user avatar
  • 341
1 vote
2 answers
7k views

Servlet and JSP for user registration, with CAPTCHA and error handling

I have a form that submits to a registration Servlet, which inserts a new user to the database when they sign up to the web application. Depending on the erroneous user input, the Servlet will ...
k_rollo's user avatar
  • 478
4 votes
1 answer
2k views

Error Handling in Servlets and JSPs

I have an HTML login form that is processed by a servlet, which then redirects the user to a result page. login.jsp: ...
k_rollo's user avatar
  • 478
5 votes
3 answers
5k views

User registration Servlet

I have a servlet that processes user registration to a website. It takes inputs from an HTML form like username, password, email, etc. MySQL Table: ...
k_rollo's user avatar
  • 478
1 vote
3 answers
34k views

A Java Web App with Servlets, JSP and Session: shopping cart example

This is the only Servlet I have: ...
Koray Tugay's user avatar
  • 1,565
2 votes
1 answer
189 views

Servlet WebClient: How do I best solve for multiple servlet requests?

This is working code presently visible here. Basically, this is still a work in process, but I do not want to go much further down the road without peer review. I've limited the source to the servlet. ...
plditallo's user avatar
  • 251
5 votes
3 answers
14k views

Unit testing a servlet in a meaningful way

I have to write a unit test for the method processRequest in the servlet below and I'm wondering if: It just shouldn't be done. The class should be rewritten / ...
DiePartei's user avatar
  • 151
6 votes
1 answer
11k views

Single Sign On - SAML Response generation

I am trying to implement a IDP initiated Single Sign On Solution (service similar to onelogin's) to Cloud based Service providers such as Google Apps, Salesforce etc. The project is a Maven eclipse ...
Raghav RV's user avatar
  • 225
3 votes
1 answer
530 views

Mutualising multi-threaded calls to EJB from Servlet

I have a Servlet that makes an EJB call to a backing server which takes about a second to return some data that changes reasonably regularly. I can't cache the data on the servlet-side, so I have ...
Rich's user avatar
  • 237
10 votes
2 answers
6k views

Simple servlet code to sum digits

This servlet takes an input from the user and Stores the number inside the bean but with spaces in between each digit then stores the bean in the request scope. If the last digit is even, sums the ...
lightning_missile's user avatar
9 votes
2 answers
1k views

MVC controller code

Please review my servlet. ...
lightning_missile's user avatar
7 votes
2 answers
11k views

Implement HTTP Server with persistent connection

I am trying to implement a HTTP Server in Java, I want the server to use a persistent connection per thread for request and response. After some research on Google, this is how my program looks like. ...
ksagar's user avatar
  • 73
10 votes
2 answers
801 views

Servlet for querying database on some high-loaded system

What should the code do: Process client HTML requests, query database and return the answer in XML. Working with a high load. I need to know how can it be optimized. Is something terribly wrong with ...
John's user avatar
  • 109
-1 votes
1 answer
856 views

Please check my example about jquery autocomple with servlet [closed]

Please check my code, did i get some things wrong I'm a newbie in jquery and ajax, please check and show me how to fix this In jsp page : ...
user2971216's user avatar
-2 votes
1 answer
6k views

file downloading using jsp but not readable [closed]

I am trying to download files using jsp but then downloaded files are not readable. Suppose if i download pdf files then it can not opened,if i download jpg files then it can not opened and similarily ...
java programmer's user avatar