<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"><web-app> <display-name>Welcome to Tomcat</display-name> <description> Welcome to Tomcat </description> <!-- Automatically created by Tomcat JspC. Place this fragment in the web.xml before all icon, display-name, description, distributable, and context-param elements. --> <servlet> <servlet-name>test.Count</servlet-name> <servlet-class>test.Count</servlet-class> </servlet> <servlet-mapping> <servlet-name>test.Count</servlet-name> <url-pattern>/servlet/test.Count</url-pattern> </servlet-mapping> <!-- All session-config, mime-mapping, welcome-file-list, error-page, taglib, resource-ref, security-constraint, login-config, security-role, env-entry, and ejb-ref elements should follow this fragment. --> 这是我root目录下的web.xml文件,按这样的配置,能运行test.Count,但新建个servlet文件就非的改web.xml吗,有没有办法使只改一次web.xml以后每次新建个servlet都能运行呢? Count的servlet如下: package test; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Count extends HttpServlet { int count; public void init(ServletConfig config) throws ServletException {super.init(config); count=0; } public synchronized void service(HttpServletRequest request,HttpServletResponse response) throws IOException { //获得一个向客户发送数据的输出流: PrintWriter out=response.getWriter(); response.setContentType("text/html;charset=GB2312");//设置响应的MIME类型。 out.println("<HTML> <BODY>"); count++; //增加计数。 out.println("you are "+count+"th"+" people"); out.println("</body> </html>"); } } 谢谢你们的答复,可是还是没解决问题,希望继续指点.
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"><web-app> <display-name>Welcome to Tomcat</display-name> <description> Welcome to Tomcat </description> <!-- Automatically created by Tomcat JspC. Place this fragment in the web.xml before all icon, display-name, description, distributable, and context-param elements. --> <servlet> <servlet-name>test.Count</servlet-name> <servlet-class>test.Count</servlet-class> </servlet> <servlet-mapping> <servlet-name>test.Count</servlet-name> <url-pattern>/servlet/test.Count</url-pattern> </servlet-mapping> <!-- All session-config, mime-mapping, welcome-file-list, error-page, taglib, resource-ref, security-constraint, login-config, security-role, env-entry, and ejb-ref elements should follow this fragment. --> 这是我root目录下的web.xml文件,按这样的配置,能运行test.Count,但新建个servlet文件就非的改web.xml吗,例如新建一个test.Hello,就不改web.xml就没办法运行.有没有办法使只改一次web.xml以后每次新建个servlet都能运行呢? Count的servlet如下: package test; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Count extends HttpServlet { int count; public void init(ServletConfig config) throws ServletException {super.init(config); count=0; } public synchronized void service(HttpServletRequest request,HttpServletResponse response) throws IOException { //获得一个向客户发送数据的输出流: PrintWriter out=response.getWriter(); response.setContentType("text/html;charset=GB2312");//设置响应的MIME类型。 out.println("<HTML> <BODY>"); count++; //增加计数。 out.println("you are "+count+"th"+" people"); out.println("</body> </html>"); } }
<servlet-name>Test</servlet-name>
<display-name>Test</display-name>
<description>A test Servlet</description>
<servlet-class>test.Test</servlet-class>
</servlet>
<servlet>
....</servlet>
....<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/Test</url-pattern>
</servlet-mapping> <servlet-mapping>
....
</servlet-mapping> 呵呵,servlet和mappin 多写几个就行了
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.InvokerServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>在前面调用时,假如你的servlet为com.db下dbCtrl.class,你的应用为app
用/app/servlet/com.db.dbCtrl进行访问
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd"><web-app>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<!--
Automatically created by Tomcat JspC.
Place this fragment in the web.xml before all icon, display-name,
description, distributable, and context-param elements.
--> <servlet>
<servlet-name>test.Count</servlet-name>
<servlet-class>test.Count</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test.Count</servlet-name>
<url-pattern>/servlet/test.Count</url-pattern>
</servlet-mapping> <!--
All session-config, mime-mapping, welcome-file-list, error-page, taglib,
resource-ref, security-constraint, login-config, security-role,
env-entry, and ejb-ref elements should follow this fragment.
-->
这是我root目录下的web.xml文件,按这样的配置,能运行test.Count,但新建个servlet文件就非的改web.xml吗,有没有办法使只改一次web.xml以后每次新建个servlet都能运行呢?
Count的servlet如下:
package test;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Count extends HttpServlet
{ int count;
public void init(ServletConfig config) throws ServletException
{super.init(config);
count=0;
}
public synchronized void service(HttpServletRequest request,HttpServletResponse response)
throws IOException
{ //获得一个向客户发送数据的输出流:
PrintWriter out=response.getWriter();
response.setContentType("text/html;charset=GB2312");//设置响应的MIME类型。
out.println("<HTML> <BODY>");
count++; //增加计数。
out.println("you are "+count+"th"+" people");
out.println("</body> </html>");
}
}
谢谢你们的答复,可是还是没解决问题,希望继续指点.
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd"><web-app>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<!--
Automatically created by Tomcat JspC.
Place this fragment in the web.xml before all icon, display-name,
description, distributable, and context-param elements.
--> <servlet>
<servlet-name>test.Count</servlet-name>
<servlet-class>test.Count</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test.Count</servlet-name>
<url-pattern>/servlet/test.Count</url-pattern>
</servlet-mapping> <!--
All session-config, mime-mapping, welcome-file-list, error-page, taglib,
resource-ref, security-constraint, login-config, security-role,
env-entry, and ejb-ref elements should follow this fragment.
-->
这是我root目录下的web.xml文件,按这样的配置,能运行test.Count,但新建个servlet文件就非的改web.xml吗,例如新建一个test.Hello,就不改web.xml就没办法运行.有没有办法使只改一次web.xml以后每次新建个servlet都能运行呢?
Count的servlet如下:
package test;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Count extends HttpServlet
{ int count;
public void init(ServletConfig config) throws ServletException
{super.init(config);
count=0;
}
public synchronized void service(HttpServletRequest request,HttpServletResponse response)
throws IOException
{ //获得一个向客户发送数据的输出流:
PrintWriter out=response.getWriter();
response.setContentType("text/html;charset=GB2312");//设置响应的MIME类型。
out.println("<HTML> <BODY>");
count++; //增加计数。
out.println("you are "+count+"th"+" people");
out.println("</body> </html>");
}
}