Career Point University Students: A Beginner’s Route Into Java Web Apps With Servlets and JSP

Facebook
Twitter
LinkedIn
WhatsApp
Email

Yes, a beginner can build a working login-and-list Java web app with Servlets, JSP and Tomcat in 14 days, if each day has one small, testable goal. This article gives that day-by-day plan, a checklist for each layer of the app, and a table showing how every piece maps to Spring Boot and Spring MVC later.

Why learn Servlets and JSP before Spring

Spring Boot hides a lot: it starts the server, maps URLs, parses form data and manages sessions for you. That is convenient, but a beginner who starts there often cannot explain what happens when a browser sends a request. Servlets and JSP expose the machinery directly. You write the class that receives the request, you read the form parameter yourself, and you decide which page comes back.

The goal is not to use outdated technology in a real job. The goal is to understand the request-response cycle so that annotations like @GetMapping or @Controller later feel like shortcuts rather than magic.

The free two-week online internship at CareerSwami runs for 14 days and has 26 tracks, which is a handy frame for this plan: one small milestone a day, ending with something you can demo. The plan below works equally well on your own.

What the finished app does

The project is deliberately small, so you finish it and understand every line:

  • A login page with username and password.
  • A servlet that checks credentials against a database table and starts a session.
  • A protected page that lists records (for example, books, courses or tasks) read from the database.
  • A form to add one new record, and a logout link.

Free 2-Week CareerSwami Internship

Online, 14 days, with a free offer letter and a free completion certificate once you finish the work. Check with your college that it fits your requirement before you enrol.

Apply for the free internship

Setup checklist before Day 1

  • JDK 17 or newer installed; confirm with java -version.
  • Apache Tomcat. Choose the version that matches your imports: Tomcat 10 and later use the jakarta.servlet package, while Tomcat 9 and earlier use javax.servlet. Mixing them is the most common beginner error.
  • Maven, and an IDE such as IntelliJ IDEA or Eclipse (or VS Code with Java extensions).
  • MySQL or PostgreSQL, plus its JDBC driver. H2 is fine if installation is a problem.
  • Git, with a repository created on Day 1 so you commit daily.

The 14-day lab plan for a Servlets and JSP login-and-list app

Day Goal Done when
1 Install tools, create a Maven war project, deploy an empty page to Tomcat Browser shows a static HTML page at localhost:8080
2 Read about HTTP: methods, status codes, headers, parameters. Inspect a request in browser developer tools You can explain GET versus POST in two sentences
3 First servlet: HelloServlet with doGet, mapped with @WebServlet URL returns text you generated in Java
4 Read request parameters; build an HTML form that posts to a servlet Servlet echoes submitted values
5 First JSP; forward from servlet to JSP using RequestDispatcher and request attributes Servlet sets data, JSP displays it
6 Create the database schema: users and one list table (e.g. books); insert sample rows SQL queries return expected rows in a client
7 JDBC connection and a first DAO class using PreparedStatement A plain Java main method prints rows from the DAO
8 Login servlet: check credentials through the DAO, create an HttpSession Valid login redirects; invalid login shows an error
9 Password hashing (bcrypt or similar library) instead of plain text Database holds hashes only
10 List servlet and JSP using JSTL c:forEach Logged-in user sees a table of records
11 Authentication filter protecting list and add URLs Direct URL access without login redirects to login
12 Add-record form, POST handling, validation, redirect after POST New record appears; refresh does not resubmit
13 Error handling, logout, connection handling cleanup, layout include for header and footer No stack traces shown to users
14 README, screenshots, final commit, short demo, Spring mapping notes Someone else can run the project from your README

Suggested project structure

src/main/java/app/
  controller/   LoginServlet, LogoutServlet, ListServlet, AddServlet
  dao/          UserDao, BookDao
  model/        User, Book
  filter/       AuthFilter
  util/         DbUtil
src/main/webapp/
  WEB-INF/views/  login.jsp, list.jsp, add.jsp
  WEB-INF/web.xml (optional)

Putting JSPs under WEB-INF means users cannot open them directly; every page must pass through a servlet. This is a good habit and mirrors how Spring MVC view resolvers work.

Layer-by-layer build checklist

Servlet layer

  • Use doGet for showing pages and doPost for changing data.
  • Set the character encoding to UTF-8 before reading parameters.
  • Never write HTML from servlets once JSP is available; servlets decide, JSPs display.

JSP layer

  • Use Expression Language (${book.title}) and JSTL; avoid scriptlets (<% %>).
  • Escape output with c:out or fn:escapeXml to prevent cross-site scripting.

Database layer

  • Always use PreparedStatement with placeholders; never concatenate user input into SQL.
  • Close connections with try-with-resources.
  • Keep SQL inside DAO classes, not servlets.

Security basics

  • Hash passwords; never store or log plain text.
  • Call session.invalidate() on logout.
  • Regenerate the session ID after login (request.changeSessionId()) to reduce session fixation risk.

Illustrative walk-through: the login servlet

This is an illustrative sketch of the shape of the code, not tested output. Adapt names to your project.

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
  private final UserDao userDao = new UserDao();

  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    req.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(req, resp);
  }

  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    String username = req.getParameter("username");
    String password = req.getParameter("password");
    User user = userDao.findByUsername(username);
    if (user != null && PasswordUtil.matches(password, user.getHash())) {
      req.changeSessionId();
      req.getSession().setAttribute("user", user);
      resp.sendRedirect(req.getContextPath() + "/books");
    } else {
      req.setAttribute("error", "Invalid username or password");
      req.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(req, resp);
    }
  }
}

Notice the sequence: read parameters, ask the DAO, decide, then either redirect (success) or forward with an error (failure). Redirect after a successful POST prevents the browser from resubmitting credentials on refresh. Write down, in your own words, why forward is used for the error and redirect for success; that single question tests whether you understand the request cycle.

How each Servlet and JSP piece maps to Spring

What you build here Spring equivalent What changes
HttpServlet subclass with @WebServlet @Controller or @RestController methods with @GetMapping/@PostMapping One class handles many URLs; Spring’s DispatcherServlet is the single servlet underneath
req.getParameter() @RequestParam, form-backing objects, @ModelAttribute Automatic binding and type conversion
req.setAttribute() and forward to JSP Model and a returned view name View resolver locates the template (JSP or Thymeleaf)
JSP with EL and JSTL Thymeleaf or JSP views; JSON in REST APIs Same idea of rendering model data
DAO with JDBC Spring Data JPA repositories or JdbcTemplate Less boilerplate; transactions managed for you
new UserDao() inside a servlet Dependency injection with @Service, @Repository, @Autowired The container creates and wires objects
HttpSession login check Spring Security with sessions or tokens Declarative rules, password encoders, CSRF protection
AuthFilter implementing Filter Spring Security filter chain, interceptors Configured centrally instead of per-URL code
Tomcat deployment of a WAR Spring Boot with embedded Tomcat, run as a JAR No separate server install needed
web.xml and manual config application.properties and auto-configuration Sensible defaults replace manual setup

A good follow-up after Day 14 is to rebuild the same app in Spring Boot over a few days. Because you already know what each layer does, you will see which of your hand-written code disappears and why.

Career Point University students: fitting this Java web lab around your coursework

Career Point University in Hamirpur, Himachal Pradesh, was established by the Government of Himachal Pradesh under Act No. 12 of 2012, and its About page lists programme areas including Engineering and Technology, Computer Applications and IT, and Artificial Intelligence and Data Science. If you are in one of those programmes, this lab complements what you study rather than replacing it. An excerpt of the B.Tech page describes a curriculum covering programming languages, databases and software engineering, which are exactly the skills a servlet-and-JDBC project exercises. Treat that as an excerpt and read the current page yourself.

The university’s Training & Placement Cell page says the cell offers career guidance and acts as an interface between students, alumni and industry. A finished project with a README and a short demo is something concrete to bring to that kind of conversation. The page does not give placement statistics, so do not assume any outcome from it.

Timing matters too. The Downloads page links an Academic Calendar 2026-27 and a July–December 2026 time table. Check those before picking your 14 days, so the lab does not collide with examinations. No internship or project-work rule was verified for this article, so do not assume that this lab counts toward anything in your scheme.

Verification steps for CPUH students

  1. Open the Academic Calendar 2026-27 PDF on the Downloads page and note exam and break dates before scheduling your 14 days.
  2. Download the scheme and syllabus PDF for your own programme and year, and check whether Java, web technology or a project course appears in your semester.
  3. Ask your department coordinator in writing whether the university or your school sets rules for internships and online internships, and whether any documentation is needed.
  4. Ask your faculty whether a Java lab environment (JDK, Tomcat, database) is available on campus machines, or whether you should use your own laptop.
  5. Email the Training & Placement Cell and ask what project evidence (repository link, demo, report) they find useful for students in your branch.

Common stumbling blocks at each stage of the lab

Symptom Likely cause Fix
HTTP 404 on a servlet URL Wrong context path or missing @WebServlet mapping Check the deployed WAR name and the mapping string
ClassNotFoundException: javax.servlet... on Tomcat 10+ Old javax imports with a jakarta server Switch imports to jakarta.servlet or use Tomcat 9
JSP shows ${...} literally EL disabled or missing JSTL dependency Add the Jakarta JSTL dependency and correct taglib URI
“No suitable driver” error JDBC driver not packaged in the WAR Add the driver as a Maven dependency
Garbled non-English text Encoding not set Call setCharacterEncoding("UTF-8") and set the JSP page encoding
Form resubmits on refresh Forwarding after POST Use sendRedirect after a successful POST
User sees login page after login Session attribute name mismatch or filter bug Log the attribute name in both places and check filter URL patterns

Daily working routine for the 14 days

  1. Spend the first 20 minutes reading about the day’s concept before touching code.
  2. Build the smallest version that works, then test it in the browser.
  3. Commit with a message that states what works now.
  4. Write two lines in a learning log: what broke, and what fixed it.
  5. Stop by planning tomorrow’s first step so you can start quickly.

On completion of the CareerSwami internship, you receive a free offer letter at the start and a free completion certificate after successful completion. The certificate is a record of participation; your repository and README are the stronger evidence of what you can actually do.

Self-check before you call the project finished

  • Can you run the app from a fresh clone using only the README?
  • Does every database call use PreparedStatement?
  • Are all passwords hashed?
  • Are all JSP files inaccessible by direct URL?
  • Can you explain, without notes, what happens between clicking Login and seeing the list?
  • Can you name the Spring feature that replaces each of your classes?

Frequently Asked Questions

Do I need to know Java well before starting this plan?

You need core Java: classes, interfaces, collections, exceptions and basic JDBC ideas. If these are shaky, spend the first two days on them and compress the later days, for example by merging Days 9 and 13 into smaller tasks.

Are Servlets and JSP still used, or are they obsolete?

You will rarely start a new project with JSP, but Servlets are the foundation under Spring MVC, and many existing enterprise applications still run on them. Learning them is mainly about understanding what frameworks do for you.

Should I use Tomcat 9 or Tomcat 10?

Either works if your imports match. Tomcat 10 and later use jakarta.servlet; Tomcat 9 uses javax.servlet. Newer learners usually do better with the Jakarta namespace because current Spring versions use it.

Can I use Spring Boot from the start instead?

You can, but you may finish without knowing what a servlet, session or filter is. Doing this plan first and then rebuilding in Spring Boot gives you both skills and makes the second build much faster.

Will this project count as academic credit at my university?

Do not assume so. The CareerSwami internship does not offer academic credit, and no CPUH internship rule was verified here. Ask your department in writing whether any external or online internship is recognised.

What database should a beginner use?

MySQL or PostgreSQL gives realistic experience. H2 or SQLite is acceptable if installation slows you down, because the DAO pattern and SQL you write stay almost the same.

How do I show this project to recruiters or faculty?

Publish the repository with a README covering setup steps, features, a schema diagram and two or three screenshots. A two-minute screen recording of login, listing and adding a record is more convincing than a long description.

What should I learn right after this project?

Rebuild the same app with Spring Boot, Spring MVC, Spring Data JPA and Spring Security. Then add unit tests with JUnit and expose a small REST API, since both are expected in most Java enterprise roles.

Related Java & Enterprise Software guides

Ready to put this into practice?

Join the free two-week CareerSwami online internship in Java & Enterprise Software. The internship, the offer letter and the completion certificate are free.

Start your free 2-week internship

Web Stories

Scroll to Top