Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the servlet is 

<pre>import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class ServletWriteHtml extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException
{
    PrintWriter out = response.getWriter();
    java.util.Date today = new java.util.Date();
    out.println("html" +
                "<body>" +
                "<h1 align = center>Write Html<h1>"
                + "<br>" + today + "<body>" + "</html>");                        
        }
}


<?xml version="1.0" encoding="UTF-8"?>
<web-app id="file-upload" 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>And</servlet-name>
        <servlet-class>ServletWriteHtml</servlet-class>
    </servlet>  
    <servlet-mapping>
        <servlet-name>ServletWriteHtml</servlet-name>
        <url-pattern>/Alfa</url-pattern>
    </servlet-mapping>
        <welcome-file-list>
            <welcome-file>index.html</welcome-file>
        </welcome-file-list>
</web-app>


compiled the servlet and put at WEB-INF folder

the url of the servlet is

[^]

HTTP Status 404 - Not Found
type Status report
messageNot Found
descriptionThe requested resource is not available.
GlassFish Server Open Source Edition 4.1.1

What I have tried:

ran the application from ide , compiled the servlet and tried the url through web browser
Posted
Updated 15-May-19 6:04am
Comments
ThilinaMD 25-Dec-17 10:26am    
For glassfish server you have to deploy the application to access the servlets

In your web xml <servlet-name>. value is different in <servlet> tag and <servlet-mapping> tag. So server cannot map to correct servlet. You have to use same servlet-name value for both servlet and servlet-mapping tags

[^Read oracle docs for more info]
<servlet>
    <servlet-name>And</servlet-name>
    <servlet-class>ServletWriteHtml</servlet-class>
</servlet>  
<servlet-mapping>
    <servlet-name>And</servlet-name>
    <url-pattern>/Alfa</url-pattern>
</servlet-mapping>


tip: reply to the comments in reply section and not as an answer.
 
Share this answer
 
v2
the ide is netbeans, glassfish server has been deployed and the application is launched from web console, .class file has been created and is at web-inf directory still the error is 404 not found
 
Share this answer
 
<servlet>
		<servlet-name>And</servlet-name>
		<servlet-class>Javas.ServletWriteHtml</servlet-class>
	</servlet>	
	<servlet-mapping>
		<servlet-name>And</servlet-name>
		<url-pattern>/Alfa</url-pattern>
	</servlet-mapping>


changed the servlet name and added ServletWriteHtml at Javas package still 404 not found
 
Share this answer
 
Comments
ThilinaMD 27-Dec-17 4:52am    
create a new servlet using new servelt wizard. Do not click on finish at first. click next and there you can add servlet info to the web.xml (check the check box) then open web xml file and examine the auto generated code about servlet mapping. Again you are posting replies as solutions. please avoid that. It will mislead other readers.
four systems 27-Dec-17 5:55am    
that was so good it works now thanks
ThilinaMD 29-Dec-17 0:18am    
welcome and happy coding

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900