2

I'm new to java web dev. I've done my research, but still couldn't figure this out on my own.

I'm trying to analyze a project, it integrates spring, struts and hibernate. Spring for POJO and basic application development, struts appear to be used for handling the requests and more "web-ish" part of the project while hibernate together with hql is used for database interfacing.

I was very, very curious about how the flow of information works, particularly for the post method. Through lengthy but rewarding studies, it appears that, after getting out of the TLS/SSL tunnel, the decrypted http (decrypted so the "s" part probably no longer exist, lol) requests (which are ascii texts) will be sent to the java objects (instantiated from java classes, likely compiled, of course) container. And these objects are usually referred to as servlets (correct me if I'm wrong).

The puzzling part pops up when I'm trying to figure out just how the container decides which servlet it gives the requests to. Again by researching it appears that it is usually handled by a configuration file called web.xml, but strangely I couldn't find any tag in this file like it is supposed to be, let alone a servlet with a name that matches the "target" name specified by the action property, shown below:

<form action="<%=context %>/handler/register"  method="post">

Yet the entire project runs just fine on the Tomcat server. the only conclusion I can draw is that there must be other ways to configure the "java object container" in the tomcat server to handle user requests. What are they?/What is it?

Also there could be a lot of mis-concept in my understanding, e.g. the whole java-class-object part, correct me if I'm wrong would you be so kind.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
  • Which part you want to explore more is not clear? Can you help to understand, which one from below you want to know 1. How the container resolve request ? 2. How the servlet or server component being configured in your scenario of spring + strut + hibernate? 3. How the html/ UI form action being redirected to the post method defined for the servlet mapped with handler/register? – Rizwan May 01 '18 at 10:29
  • Hello, thank you for your reply, if I can only choose 1, I'd say it's number 1, how on earth does container know which serverlet to pass the request it just received to. I know one conventional way to do it is to use tag and define everything in web.xml, but my project's web.xml has no such thing. – Akuzuki29087 May 01 '18 at 10:42
  • What's your application web/folder structure look like. This might of help? https://stackoverflow.com/questions/3106452/how-do-servlets-work-instantiation-sessions-shared-variables-and-multithreadi – Rizwan May 01 '18 at 14:19
  • You should really read the [servlet specification](https://javaee.github.io/servlet-spec/downloads/servlet-4.0/servlet-4_0_FINAL.pdf). It's quite readable and will answer all questions posed above. – Christopher Schultz May 06 '18 at 15:08

1 Answers1

0

Since version 3.0 of the Servlet specification, you can also use annotations to tell the server where your servlets are.

In the code, you're looking for something like:

@WebServlet("/handler/register")
public class SomeRandomServlet extends HttpServlet
Moose Morals
  • 1,628
  • 25
  • 32