servlet映射的问题,HTTP Status-404 10C

index.jsp


web.xml
<?xml version="1.0" encoding="UTF-8"?>


filter
com.May_8


filter
/*


word
com.NoteServlet


word
/NoteWord


NoteServlet.java
package com;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**

  • Servlet implementation class NoteServlet
    */
    @WebServlet("/NoteServlet")
    public class NoteServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public NoteServlet() {
    super();
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding("UTF-8");
    PrintWriter out=response.getWriter();
    out.println();
    out.close();
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=utf-8");
    PrintWriter out = response.getWriter();
    out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
    out.println("");
    out.println("

    A Servlet");
    out.println(" ");
    String name = request.getParameter("username");
    if(name==null || name.trim().length()<=0){
        out.println("�字�能为空!!!");
    }else{
        String words = request.getParameter("name");
        out.println("<br/>"+name+"的留言是:<br/>"+ words);
    }
    out.println("  </BODY>");
    out.println("</HTML>");
    out.flush();
    out.close();
    

    }

}
May_8.java
package com;

import java.io.IOException;
import java.util.List;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import com.WordUtil;
public class May_8 implements Filter{

public void init(FilterConfig arg0) throws ServletException {   
}
public void destroy(){  
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
request.setCharacterEncoding("UTF-8");
MyRequest req=new MyRequest((HttpServletRequest)request);
chain.doFilter(req, response);

}

class MyRequest extends HttpServletRequestWrapper

{

    public MyRequest(HttpServletRequest request) {
        super(request);

    }
    public String getParameter(String name){
        String str=super.getParameter(name);
        List<String>list=WordUtil.getWord();
        for(String word:list){
            str=str.replace(word,"*");
        }
        return str;
    }
}

}
图片说明
图片说明

0

2个回答

路径不对,你右击index.jsp 选最后一个看一下路径,你ma y_8下面没有NoteWord, 把NoteWord去了,再试试,或者去了加上index.jsp试试

0
wushengchenyu
精通拼写ssm 回复yi握不住的沙: Noteword 不是随便写的吗?写得和form action 里的一样。后面加什么?是Jsp 页面吗?
大约一年之前 回复

你是在web.xml文件当中配置了 并且使用了Webservlet标签是么? 如果是的话你可以试试把标签去掉

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!