<url-pattern></url-pattern>中间为什么写的是/com/MyServlet啊
packagecom;importjava.io.IOException;importjava.io.PrintWriter;importjavax.servlet.Se...
package com;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException {
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
out.println("保护环境!爱护地球!");
}
}
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/com/MyServlet</url-pattern>
</servlet-mapping> 展开
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException {
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
out.println("保护环境!爱护地球!");
}
}
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/com/MyServlet</url-pattern>
</servlet-mapping> 展开
展开全部
这个无妨的,你想怎么写怎么写,你可以把/com/MyServlet改成/myservlet,/myservlet.html,/hello.html,/nice.do等等都行,随便你,知识访问的时候的url不一样,比如你最初始的就应该是localhost:8080/你的项目名/com/MyServlet(注意大小写),改成什么就把/com/MyServlet换成什么,比如localhost:8080/你的项目名/hello.html.友情提示前面的斜杠“/”不能丢
追问
什么叫项目名啊。。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询