在E盘建一个tomcat虚拟目录,在web-inf里建一个classes文件夹,在里面编写HelloServlet.java文件
package org.yj.ServletDemo1;import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;class HelloServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
java.io.IOException{
PrintWriter out=resp.getWriter(); out.println("<html>");
out.println("<title>");
out.println("mldnJAVA");
out.println("</title>");
out.println("<body>");
out.println("</body>");
out.println("</html>");
out.close(); }
}这段代码编译通过了,然后我配置web-inf下web.xml。
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--><web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"> <display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>org.yj.ServletDemo1.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/helloServlet</url-pattern>
</servlet-mapping></web-app>奇怪的是,这时候启动tomcat就出错误,而且还直接关闭,根本看不到什么错误。
如果不配置xml就可以启动正常
这配置有问题?
package org.yj.ServletDemo1;import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;class HelloServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
java.io.IOException{
PrintWriter out=resp.getWriter(); out.println("<html>");
out.println("<title>");
out.println("mldnJAVA");
out.println("</title>");
out.println("<body>");
out.println("</body>");
out.println("</html>");
out.close(); }
}这段代码编译通过了,然后我配置web-inf下web.xml。
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--><web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"> <display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>org.yj.ServletDemo1.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/helloServlet</url-pattern>
</servlet-mapping></web-app>奇怪的是,这时候启动tomcat就出错误,而且还直接关闭,根本看不到什么错误。
如果不配置xml就可以启动正常
这配置有问题?
解决方案 »
- 大虾们棒棒忙啊!一个关于Tomcat的问题!
- 日期型可不可以转化为Calendar型,比如:Fri Sep 16 00:00:00 CST 2005 可不可以转化Calendar型,
- 怎摸判断输入的邮件名称是合法的,包括全角及半角的判断。有现成的程序更好。谢谢。
- session小问题...
- JSP页面优化
- 大家帮我看看这个程序为什么编译不过去呢
- (求救)调试login.jsp时出错
- 紧急求助!!!在线等待。
- 一个简单的难题!
- 如何将<a>标签中href属性映射到Controller中?
- NestedServletException: Request processing failed; nested exception i
- 求助session对性能的影响
at org.apache.tomcat.util.net.AprEndpoint.init(AprEndpoint.java:649)
at org.apache.coyote.http11.Http11AprProtocol.init(Http11AprProtocol.java:107)
at org.apache.catalina.connector.Connector.initialize(Connector.java:1022)
at org.apache.catalina.core.StandardService.initialize(StandardService.java:703)
at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:838)
at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
at org.apache.catalina.startup.Catalina.load(Catalina.java:562)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2011-10-28 9:16:19 org.apache.catalina.core.StandardService initialize
严重: Failed to initialize connector [Connector[HTTP/1.1-80]]
LifecycleException: Protocol handler initialization failed: java.lang.Exception: Socket bind failed: [730048] ?????????×???(Э?é/???????/???)????í??
at org.apache.catalina.connector.Connector.initialize(Connector.java:1024)
at org.apache.catalina.core.StandardService.initialize(StandardService.java:703)
at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:838)
at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
at org.apache.catalina.startup.Catalina.load(Catalina.java:562)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2011-10-28 9:16:19 org.apache.coyote.ajp.AjpAprProtocol init
严重: Error initializing endpoint
java.lang.Exception: Socket bind failed: [730048] ?????????×???(Э?é/???????/???)????í??
at org.apache.tomcat.util.net.AprEndpoint.init(AprEndpoint.java:649)
at org.apache.coyote.ajp.AjpAprProtocol.init(AjpAprProtocol.java:160)
at org.apache.catalina.connector.Connector.initialize(Connector.java:1022)
at org.apache.catalina.core.StandardService.initialize(StandardService.java:703)
at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:838)
at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
at org.apache.catalina.startup.Catalina.load(Catalina.java:562)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2011-10-28 9:16:19 org.apache.catalina.core.StandardService initialize
严重: Failed to initialize connector [Connector[AJP/1.3-8009]]
LifecycleException: Protocol handler initialization failed: java.lang.Exception: Socket bind failed: [730048] ?????????×???(Э?é/???????/???)????í??
at org.apache.catalina.connector.Connector.initialize(Connector.java:1024)
at org.apache.catalina.core.StandardService.initialize(StandardService.java:703)
at org.apache.catalina.core.StandardServer.initialize(StandardServer.java:838)
at org.apache.catalina.startup.Catalina.load(Catalina.java:538)
at org.apache.catalina.startup.Catalina.load(Catalina.java:562)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:261)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2011-10-28 9:16:19 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1465 ms