Where is the Invalid Content in Servlet Mapping - java

Getting the following erorr for invalid url pattern. Trying to follow this tutorial from Telusko exactly. https://www.youtube.com/watch?v=wty6OROO__8&list=PLsyeobzWxl7pUPF2xjjJiG4BKC9x_GY46&index=6
The action attribute in my form is set to "add" and I've tried with and without the forward slash without success. Please help. Thank you.
cvc-complex-type.2.4.a: Invalid content was found starting with element 'servlet-mapping'. One of '{"http://
xmlns.jcp.org/xml/ns/javaee":url-pattern}' is expected.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>com.centeno.AddServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<servlet-mapping>/add</servlet-mapping>
</servlet-mapping>
</web-app>

Try url-pattern, not servlet-mapping inside tag servlet-mapping
<servlet-mapping>
<servlet-name></servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>

Related

Unable to map servlet

I am starting with servlets and I am trying to get 2 numbers from a form and add them using java logic but when running it is showing The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. So I am guessing it is mapping problem can someone help?
Here is my web.xml code
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>Addition</display-name>
<servlet>
<servlet-name>addNum</servlet-name>
<servlet-class>addLogic.sum</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>addNum</servlet-name>
<url-pattern>/add</url-pattern>
</servlet-mapping>
</web-app>
Also an image of project explorer for mapping

How to map jsp class in web.xml?

I am trying to map my compiled jsp class which is available in org.apache.jsp folder in tomcat server folder to the web.xml file so that I don't want to ship my jsp code.
I am using following code, but getting HTTP Status 404 -. I cross checked, paths are correct and class files are also available in that path I don't know why i am getting this error.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<servlet-class>org.apache.jsp.index_jsp</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
</web-app>
Can any one help me to fix this?
you must use jsp-file tag for jsp mapping in web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<jsp-file>org.apache.jsp.index_jsp.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<url-pattern>/index_jsp.jsp</url-pattern>
</servlet-mapping>

I want to call a Servlet as a very first file

I want to call a Servlet as a very first file to execute like welcome file.
In this servlet I am retrieving data from database and rendering it to display page at a very first page.
what I need is when I run program
either
url should be-http://localhost:8083/projectName/servletUrl
not http://localhost:8083/projectName/
or
if url is http://localhost:8083/projectName this should hit my servlet(/servletUrl) not welcome file.
Edit this file WebContent->WEB-INF->lib->web.xml.
It will only be visible if you have ticked the Generate web.xml deployment descriptor while creating the project.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID"
version="3.1">
<display-name>Database_Conn</display-name>
<welcome-file-list>
<welcome-file>ServletURLpattern</welcome-file>
</welcome-file-list>
</web-app>
Configure your servlet URLpattern as <welcome-file> in web.xml file located in WEB-INF folder of webapp like below:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>ProjectName</display-name>
<welcome-file-list>
<welcome-file>ServletURLpattern</welcome-file>
</welcome-file-list>
</web-app>
Assuming you use eclipse as IDE and servlet version 3 or 3.1 than you have to create web.xml manually.
I have used such servlet mapping:
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
The key part is URL pattern that matches all possible URLs unless you add another servlet-mapping for other servlets.
<servlet>
<servlet-name>PenServlet</servlet-name>
<servlet-class>com.sun.PenServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
Here load-on-startup is an attribute of web.xml that will loaded first
if it has a lowest Integer Number.for example if you have 3 servlet that
is mentioned in the web.xml like
<servlet>
<servlet-name>PenServlet1</servlet-name>
<servlet-class>com.sun.PenServlet1</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>PenServlet0</servlet-name>
<servlet-class>com.sun.PenServlet0</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet>
<servlet-name>PenServlet2</servlet-name>
<servlet-class>com.sun.PenServlet2</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
Here then load-on-startup 0 is loaded first in your web application
then 1 and 2 and so on..
you need to use this to get data and set it to your first page or return
your page from servlet with loaded data.

404 Not Found error was encountered while trying to use an ErrorDocument to handle the request

I am developing a website and i am finding hosting issues. I have put all my .jsp files in the root directory.
I am able to see the JSPs (accessing directly to them).
But, when i try to perform the same check the WEB-INF/classes, I get the error:
Not Found The requested URL /AC/SearchController was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
This is my Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>AC</display-name>
<welcome-file-list>
<welcome-file>Home.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>AdvisorProfileServlet</servlet-name>
<servlet-class>org.AC.controller.AdvisorProfileServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdvisorProfileServlet</servlet-name>
<url-pattern>/AC/AdvisorProfilePage?aId=*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ForgotPasswordRedirectController</servlet-name>
<servlet-class>org.AC.controller.ForgotPasswordURLController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ForgotPasswordRedirectController</servlet-name>
<url-pattern>/ForgotPasswordAdvisor</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>AdvisorMyAccountRequest</servlet-name>
<servlet-class>org.AC.controller.AdvisorMyAccountRequestController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdvisorMyAccountRequest</servlet-name>
<url-pattern>/AC/requests.jsp</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ForgotPasswordRedirectControllerUser</servlet-name>
<servlet-class>org.AC.controller.UserForgotPasswordURLController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ForgotPasswordRedirectControllerUser</servlet-name>
<url-pattern>/ForgotPasswordUser</url-pattern>
</servlet-mapping>
</web-app>
This might also be a server config, because I created the project on Tomcat server 8, but I guess the server which is now hosting it is Tomcat 7.
How can I resolve this?
Please declare "/AC/SearchController" as url pattern in your web.xml

remove .py from the jython based web application url

This is the follow up of this question how to remove .py from the url in jython , I couldnt get it solved till now, and hope to get some more suggestions for it.
Here is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
<servlet>
<servlet-name>PyServlet</servlet-name>
<servlet-class>org.python.util.PyServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>PyServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>NewJythonServlet</servlet-name>
<servlet-class>NewJythonServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>NewJythonServlet</servlet-name>
<url-pattern>/NewJythonServlet</url-pattern>
</servlet-mapping>
</web-app>
any ideas please?
Try:
<servlet-mapping>
<servlet-name>PyServlet</servlet-name>
<url-pattern>/serv/*</url-pattern>
</servlet-mapping>
I think the url had to start with something that isn't a wildcard

Categories