The story that the Servlet could not be loaded in the Java Web application

I had to do a little data editing work, so I decided to create a simple Web application and proceed with the GUI. Since I use it personally, I don't have to worry about maintainability. Anyway, I just need to make it quickly. Since Eclipse was installed in the terminal, I will make a dynamic web application in Java with Eclipse. Create a project or Servlet from a template, and then code it.

However, when I try to access Java Servlet with ajax from jsp, it does not respond. This was a big problem.

<web-app>
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
</web-app>
$ajax({
	url:'/testapp/test',
	type:'POST',
	data:{
		'param1':'aaa',
		'param2':'bbb'
	}
})
.done((data)=> {console.log("done!");})
.fail((data)=> {console.log("fail!");})
.always((data)=> {console.log("always!");})
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
	public TestServlet() {...}
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {...}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {...}
}
fail!
always!

I couldn't reach TestServlet and I have no idea what caused it. So, when I looked closely, I was curious about the @WebServlet ("/ TestServlet ") that was included when TestServlet.java was automatically generated. Good grief. I searched.

[Specify URL pattern with @WebServlet] (https://code-examples-ja.hateblo.jp/entry/2015/10/22/%40WebServlet%E3%81%A7URL%E3%83%91%E3%82%BF%E3%83%BC%E3%83%B3%E3%82%92%E6%8C%87%E5%AE%9A)

Gorgeous. You don't have to write web.xml ... I deleted the description of web.xml and changed the ajax url to '/ testapp / TestServlet' and it worked without difficulty.

If you usually rely on frameworks and templates, you will become a fossil engineer. Daily study clearly appears in the development speed at the moment of emergency.

Recommended Posts

The story that the Servlet could not be loaded in the Java Web application
The story that the forced update could not be implemented
The case that @Autowired could not be used in JUnit5
The story that the variable initialization method called in the Java constructor should not be overridden
Correspond to "error that basic authentication does not pass" in the test code "The story that could not be done"
About the case that ("b" .. "aa") could not be used in Ruby Range
The story that I could not build after installing multiple Java on Windows
The story that .java is also built in Unity 2018
[Gradle] The story that the class file did not exist in the jar file
[Java] Main class XXX was not found or could not be loaded
[Probably the easiest] WEB application development with Apache Tomcat + Java Servlet
The story of stopping because the rails test could not be done
The story of writing Java in Emacs
Role of JSP in Web application [Java]
Story when migration could not be done
Web application structure by Java and processing flow in the presentation layer
[Java] The story that the expected array was not obtained by the String.split method.
The case that "apt-get update" defined in "Dockerfile" could not be done at the time of "docker-compose build"
The story of low-level string comparison in Java
The story of making ordinary Othello in Java
[CentOS8] Since the javac command could not be used, install the java development environment.
A story about the JDK in the Java 11 era
The story of learning Java in the first programming
[Java / PostgreSQL] Connect the WEB application to the database
Solved the problem that the test could not be executed from the command line with spring-boot-starter-test
Java Error Handling Basics-The story that catch is only picked up in the foreground
Write a class that can be ordered in Java
Fixed the phenomenon that vuetify built in Rails is not loaded when page transition is done
[Java] Coverage report could not be created with the combination of default method of Cobertura + interface
"The Language Support for Java server crashed 5 times in the last 3 minutes. The server will not be restarted."
Solved the problem that apt-get update could not be executed on Ubuntu (Virtual Box) on Windows.
"Error: Main class XXX not found or could not be loaded" occurs even though the main class exists
[Java] It seems that `0 <hoge <10` cannot be written in the conditional expression of the ʻif` statement.
A program (Java) that outputs the sum of odd and even numbers in an array
Sample program that returns the hash value of a file in Java
The story that the Servlet could not be loaded in the Java Web application
I didn't know that inner classes could be defined in the [Java] interface
The story when the test folder was not created in Rails
Let's make a calculator application in Java ~ Display the application window
Web application development environment construction in Java (for inexperienced people)
Identify threads in the Java process that are wasting CPU
Sample web application that handles multiple databases in Spring Boot 1.5
Java 14 new features that could be used to write code
[Docker] The story that an error occurred in docker-compose up
[Development log ⑬] Do not let 0 be entered in the form !!
About the solution to the problem that the log of logback is not output when the web application is stopped
Reference memo / In-memory LDAP server that can be embedded in Java
Comparison of WEB application development with Rails and Java Servlet + JSP
Three reasons why wrapper classes should not be used in Java
First web application co-production (unfinished) (scheduled to be completed in December)
The story of not knowing the behavior of String by passing Java by reference
Solved the problem that the scroll event did not fire in JQuery
Summary of ORM "uroboroSQL" that can be used in enterprise Java
What to do when the changes in the Servlet are not reflected
Summary of problems that I could not log in to firebase
Note that system properties including JAXBContext cannot be used in Java11
Automatically deploy a Web application developed in Java using Jenkins [Preparation]
Automatically deploy Web applications developed in Java using Jenkins [Tomcat application]
Note that Insert could not be done with Spring Data JDBC
It seems that data class-like functions will be added in Java14
A story that struggled with the introduction of Web Apple Pay
The story that Tomcat suffered from a timeout error in Eclipse
Determine if the strings to be compared are the same in Java
Let's create a TODO application in Java 5 Switch the display of TODO