| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2636 人关注过本帖
标题:练习写Servlet时出错,哪里出问题了?
只看楼主 加入收藏
fadai
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-10-14
收藏
 问题点数:0 回复次数:8 
练习写Servlet时出错,哪里出问题了?
报错如下:
信息: Reloading this Context has started
2008-1-9 12:32:33 org. endElement
严重: End event threw exception
java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.(MethodUtils.java:216)
    at org.(CallMethodRule.java:505)
    at org.(Rule.java:276)
    at org.(Digester.java:1058)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.(Digester.java:1548)
    at org.apache.catalina.startup.ContextConfig.applicationConfig(ContextConfig.java:263)
    at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:624)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:216)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4290)
    at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3043)
    at org.apache.catalina.startup.HostConfig.restartContext(HostConfig.java:873)
    at org.apache.catalina.startup.HostConfig.checkContextLastModified(HostConfig.java:759)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1085)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:327)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.StandardHost.backgroundProcess(StandardHost.java:800)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1619)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1628)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1608)
    at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> hello in servlet mapping
    at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:2238)
    at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:2214)
    ... 32 more
2008-1-9 12:32:33 org.apache.catalina.startup.ContextConfig applicationConfig
严重: Parse error in application web.xml
java.lang.IllegalArgumentException: Invalid <url-pattern> hello in servlet mapping
    at org.(Digester.java:2540)
    at org.(Digester.java:2566)
    at org.(Digester.java:1061)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.(Digester.java:1548)
    at org.apache.catalina.startup.ContextConfig.applicationConfig(ContextConfig.java:263)
    at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:624)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:216)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4290)
    at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3043)
    at org.apache.catalina.startup.HostConfig.restartContext(HostConfig.java:873)
    at org.apache.catalina.startup.HostConfig.checkContextLastModified(HostConfig.java:759)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1085)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:327)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.StandardHost.backgroundProcess(StandardHost.java:800)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1619)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1628)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1608)
    at java.lang.Thread.run(Thread.java:595)
2008-1-9 12:32:33 org.apache.catalina.startup.ContextConfig applicationConfig
严重: Occurred at line 14 column 20
2008-1-9 12:32:33 org.apache.catalina.startup.ContextConfig start
严重: Marking this application unavailable due to previous error(s)
2008-1-9 12:32:33 org.apache.catalina.core.StandardContext start
严重: Error getConfigured
2008-1-9 12:32:33 org.apache.catalina.core.StandardContext start
严重: Context startup failed due to previous errors
搜索更多相关主题的帖子: Servlet java 练习 commons reflect 
2008-01-09 12:44
doughty
Rank: 1
等 级:新手上路
帖 子:372
专家分:0
注 册:2007-10-18
收藏
得分:0 
你的错误多啊,,,还是用个断点试试,,要不把代码贴上
2008-01-09 14:32
fadai
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-10-14
收藏
得分:0 
在ecilpse上编写的
servlet代码:
package com.sh7;
import *;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorldServlet extends HttpServlet
{
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        response.setContentType("text/html;charset=gb2312");
        PrintWriter out = response.getWriter();

        out.println("<html>");
        out.println("<head>");
        out.println("<title>HelloWorld</title>");
        out.println("</head>");
        out.println("<body bgcolor=\"white\">");
        out.println("<hr>");
        out.println("HelloWorld");
        out.println("你好!世界");
        out.println("</body></html>");
    }
    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        doGet(request,response);
    }
        
}

XML代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
    xmlns="http://java.
    xmlns:xsi="http://www.
    xsi:schemaLocation="http://java.
    [url]http://java.[/url]">
    <servlet>
        <servlet-name>HelloWorldServlet</servlet-name>
        <servlet-class>com.sh7.HelloWorldServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>HelloWorldServlet</servlet-name>
        <url-pattern>hello</url-pattern>
    </servlet-mapping>
</web-app>

2008-01-09 14:46
fadai
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-10-14
收藏
得分:0 
断点怎么用?我是初学,很多东西不懂……
怎样能看懂这些错误提示?有没有参考资料可以学习?

2008-01-09 14:51
doughty
Rank: 1
等 级:新手上路
帖 子:372
专家分:0
注 册:2007-10-18
收藏
得分:0 
你需要配置....以这hello为名////
2008-01-09 17:16
fadai
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-10-14
收藏
得分:0 
是我的xml文件配置错误么?
能详细说明一下么?

2008-01-09 17:23
wanfeng2007
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-1-9
收藏
得分:0 
你的xml没有错
2008-01-09 18:13
wanfeng2007
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-1-9
收藏
得分:0 
好像是你的服务器配置问题
2008-01-09 18:16
zmp800
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-4-1
收藏
得分:0 
你的url-pattern配置错了,<url-pattern>hello</url-pattern>路径必须是以/为开始的,配置成<url-pattern>/hello</url-pattern>再试试,/代表web项目的根路径
2012-04-01 14:43
快速回复:练习写Servlet时出错,哪里出问题了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022846 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved