java servlet报404,HTTP状态404 - 未找到java servlet

the servlet is

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" +

"

" +

"

Write Html

"

+ "
" + today + "

" + "");

}

}

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

And

ServletWriteHtml

ServletWriteHtml

/Alfa

index.html

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

解决方案

In your web xml . value is different in tag and 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]

And

ServletWriteHtml

And

/Alfa

tip: reply to the comments in reply section and not as an answer.

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

And

Javas.ServletWriteHtml

And

/Alfa

changed the servlet name and added ServletWriteHtml at Javas package still 404 not found

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值