0

I am learning how to create dynamic web applications in Java. I am having some trouble understanding how to connect the JSP files, XML files, and servlet together.

Here are files from my current project, which results in a 404 resource not found error.

  1. Servlet - Assumption: the servlet file needs no reference to the jsp or xml because I am formatting using a web.xml instead of annotations.

  2. XML - Assumption A: welcome-file tag must connect to "fileName.jsp". Assumption B: url-pattern tag must contain "/nameOfJSPMinusFileExtension"

    <servlet-mapping>
        <servlet-name>LoginServlet</servlet-name>
        <url-pattern>/login</url-pattern>
    </servlet-mapping>
    
  3. JSP - Assumption: the action property in the form tag must contain "/nameOfJSPFile"

The aforementioned configuration yields the following: 404 resource not found error on the HTTP page

Could anyone explain the flow of these files and their annotations in terms of how they relate to one another to form the dynamic web app? I and others might benefit from understanding the relationship between the three.

  • 1
    What documents or books have you read? If none, what tutorials have you accomplished? What exactly was there not clear? Then such question can be answered here. – mentallurg May 24 '20 at 21:00
  • @mentallurg Pardon if that is a broad question. I have instructors who help teach, but I was hoping for someone to explain the flow in how the web app loads based on its various files. Are there tutorials you recommend? –  May 24 '20 at 21:03
  • 1
    It is a matter personal preferences. Just google for *javaee servlets jsp tomcat tutorial*. You will see from very brief ones like this https://www.codejava.net/java-ee/servlet/java-servlet-quick-start-tomcat-xml-config or this https://www.baeldung.com/jsp to more solid ones like this https://docs.oracle.com/javaee/5/tutorial/doc/bnafd.html and this https://docs.oracle.com/javaee/5/tutorial/doc/bnagx.html (they are related to Java EE 5, but can be good to start). – mentallurg May 24 '20 at 21:54

1 Answers1

0

My configuration was correct. Here is what resolved my error: right click project directory in eclipse -> run server. (I had been trying to right click and run from only the servlet class).

If anyone still wants to elaborate on how xml/jsp/servers connect, feel free.