I cant able to run Servlets and fix this error

I created a Maven web project and tried everything, but this error is not going away. However, when I created JSP files, everything worked fine. But when I tried to create a servlet and imported from Jakarta, I got a 404 Not Found error. I also tried importing from javax, but the same error occurred. I checked the Targeted Runtime, and it's set to Apache Tomcat 10.1 with Jakarta 6.1. In Project Facets, I changed the Dynamic Web Module from 2.3 to 5.0. My JDK version is 23, but after these changes, the situation got even worse. Now, I'm getting a Catalina Lifecycle Exception and an Illegal Argument Exception.
No description
29 Replies
JavaBot
JavaBotā€¢4w ago
āŒ› This post has been reserved for your question.
Hey @Mohd Waqar! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1stā€¢4w ago
It seems like you are mixing Java EE and Jakarta EE. Maje sure your web.xml is configured for Jakarta EE
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
How can i configured this in my web xml
dan1st
dan1stā€¢4w ago
Can you show your web.xml? I think you have old Java EE references there
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
Ok wait
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
No description
dan1st
dan1stā€¢4w ago
yes, line 2 and 3
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
Okayy I need to change them that means
dan1st
dan1stā€¢4w ago
Stack Overflow
Updating "web.xml" when transitioning from Java Servlet 4 to Jakart...
I am transitioning a simple Servlet from using Java Servlet 4 to Jakarta Servlet 5. I noticed my web.xml file has references to the 4 spec. <?xml version="1.0" encoding="UTF-8&quo...
dan1st
dan1stā€¢4w ago
essentially start with
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0">
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0">
or possibly
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_1.xsd"
version="6.1">
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_1.xsd"
version="6.1">
since you said you are actually using 6.1 I think
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
Yess
dan1st
dan1stā€¢4w ago
Though I think you should use Jakarta Servlet 6.0 with Tomcat 10.1 and Jakarta Servlet 6.1 with Tomcat 11
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
Okayy i changed the jakarta version and the web xml file the red marks from my files are gone but its showing again error
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
No description
dan1st
dan1stā€¢4w ago
Can you show your new web.xml and also the full output shown in the console tab? btw please don't use screenshots for text but instead use code blocks
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
Okay
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>SaveNoteServlet</servlet-name>
<servlet-class>com.servlets.SaveNoteServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SaveNoteServlet</servlet-name>
<url-pattern>/SaveNoteServlet</url-pattern>
</servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>SaveNoteServlet</servlet-name>
<servlet-class>com.servlets.SaveNoteServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SaveNoteServlet</servlet-name>
<url-pattern>/SaveNoteServlet</url-pattern>
</servlet-mapping>
</web-app>
dan1st
dan1stā€¢4w ago
The servlets named [SaveNoteServlet] and [com.servlets.SaveNoteServlet] are both mapped to the url-pattern [/SaveNoteServlet] which is not permitted
Do you use annotations for SaveNoteServlet?
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
Yess
dan1st
dan1stā€¢4w ago
you should only declare these things once either with annotations or in the web.xml so you can just remove the <servlet> and <servlet-mapping> elements from your web.xml
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
Okayy Broo You are geniuss Its totally running fineee
dan1st
dan1stā€¢4w ago
I have just seen these things before
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
Okayy
ayylmao123xdd
ayylmao123xddā€¢4w ago
daniel loves when people call him 'your sudoness' you should say it to show how grateful you are for solving the problem šŸ˜± purely optional though
dan1st
dan1stā€¢4w ago
I don't
Waqarrrrrr
WaqarrrrrrOPā€¢4w ago
Well i am new to this community so i need to learn things šŸ˜­
ayylmao123xdd
ayylmao123xddā€¢4w ago
no worries you can learn along the way
JavaBot
JavaBotā€¢4w ago
Post Closed
This post has been closed by <@1077604975741505716>.

Did you find this page helpful?