Tomcat里怎么配才能运行Servlet

DaNiao 2003-08-18 03:31:32
我的Servlet放在我自己的目录里就不能访问
放在Tomcat安装时创建的examples目录里就可以
我猜是我配的不对
哪位大哥能教教我?
顺便问一下关于那些xml的说明在哪能找到?
...全文
63 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
DaNiao 2003-08-20
  • 打赏
  • 举报
回复
算了,我已经知道怎么配了,您几位说的都不对
archangelye 2003-08-20
  • 打赏
  • 举报
回复
:)
allan1031 2003-08-19
  • 打赏
  • 举报
回复
编译的时候有没有把 tomcai_install_path/common/lib/servlet.jar
加进去?
源文件里有没有PACKAGE
archangelye 2003-08-18
  • 打赏
  • 举报
回复
请问你的tomcat是什么版本?
如果是4.0版本的。肯定没问题。

如果是tomcat4.0,建新的应用很容易,根本不用自己改什么xml文件。
在webapps下建一个文件夹。取名为你想要的,譬如myProject,然后把
webapps下的ROOT文件夹里的东西全部拷贝到myProject下,而后重启
tomcat服务器,你的应用就建好了。
访问:
http://localhost:8080/myProject
ok
DaNiao 2003-08-18
  • 打赏
  • 举报
回复
我自己建了一个目录,并且在server.xml里做了设置
JSP可以访问,但servlet不可以(我当然在路径里加了servlet)

to smartzhang(每天多学一点) :
我把.class文件copy到 \webapps\examples\WEB-INF\classes目录里
没有改任何的设置(包括web.xml),就可以访问servlet了,一点问题也没有
所以我怀疑你说的那些是不是minimal configuration necessary to run my servlet

我把.class文件copy到我自己的目录里,不能访问
我在我的web.xml里加了那些东西,还是不能访问。。。。???
wkliangsdqd 2003-08-18
  • 打赏
  • 举报
回复
mark!
archangelye 2003-08-18
  • 打赏
  • 举报
回复
注意class拷贝时要把它的包文件夹一起拷贝进去。
如上例:com\angel\myServlet.class
archangelye 2003-08-18
  • 打赏
  • 举报
回复
1)首先你建的目录(webapps下的文件夹)有效吗?
2)如果有效。
假设:
你的目录名:ptt
servlet class: com.angel.myServlet(package名字为com.angel)

只要把这个class拷贝到WEB-INF下的classes文件夹中,然后重启服务器。

用下面的路径就可访问:
http://localhost:8080/ptt/servlet/com.angel.myServlet

主意要在前面加虚拟的一级“servlet”路径。

不需要在xml中做什么配置。
mingjob 2003-08-18
  • 打赏
  • 举报
回复
see:

http://www.csdn.net/develop/read_article.asp?id=20485
smartzhang 2003-08-18
  • 打赏
  • 举报
回复
web.xml is the web application deployment descriptor. It defines everything about your application that a server needs to know.
<?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>
<servlet>
<servlet-name>YourServlet</servlet-name>
<servlet-class>yourServletPackage.YourServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>YourServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

This is the minimal configuration necessary to run your servlet.


The tags servlet and servlet-mapping are associated with each other by the common tag servlet-name which uniquely identifies a particular servlet.

The servlet-class tag within servlet contains a fully qualified name of a servlet class. The url-pattern tag within servlet-mapping translates a particular request URI to the specified servlet class.

In the section How to call your web application from browser you will learn how to use this mapping.

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧