Click here to Skip to main content
14,084,762 members
Rate this:
 
Please Sign up or sign in to vote.
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 3 days ago
Comments
ThilinaMD 25-Dec-17 10:26am
   
For glassfish server you have to deploy the application to access the servlets
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
   
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

<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
   
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190518.1 | Last Updated 15 May 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100