2012-03-02 117 views
1

我有兩個servlet,可以很好地與Tomcat7/Indigo配合使用, 當我訪問myhost/DynamicAddServlet/tobeadded.jsp時,它會打印'已添加'。動態添加WebLogic 12c中的servlet無法正常工作?

但是他們不能在WebLogic 12c中工作,WebLogic 12c中可以這麼做嗎?

AddServletServlet

package test.servlets; 

import java.io.IOException; 
import java.util.*; 

import javax.servlet.ServletException; 
import javax.servlet.ServletRegistration; 
import javax.servlet.annotation.WebServlet; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

@WebServlet(name="AddServletServlet", urlPatterns={"/add.jsp"}, 
loadOnStartup=1) 
public class AddServletServlet extends HttpServlet { 
/** 
* 
*/ 
private static final long serialVersionUID = -8873939883201271898L; 

    @Override 
    public void init() throws ServletException { 
     super.init(); 
     final ServletRegistration.Dynamic dn = 
       this.getServletContext().addServlet("TobeAddedServlet", TobeAddedServlet.class); 
      dn.setAsyncSupported(true); 
      dn.addMapping("/tobeadded.jsp"); 
      System.out.println(" ... init ..."); 
    } 
    @Override 
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
      throws ServletException, IOException { 

    } 
} 

TobeAddedServlet

package test.servlets; 

import java.io.IOException; 

import javax.servlet.ServletException; 
import javax.servlet.ServletRegistration; 
import javax.servlet.annotation.WebServlet; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

public class TobeAddedServlet extends HttpServlet { 
/** 
* 
*/ 
private static final long serialVersionUID = -8873939883201271898L; 

    @Override 
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
      throws ServletException, IOException { 
     System.out.println(" is added"); 
    } 
} 

堆棧跟蹤中的WebLogic 12c中:

<Mar 2, 2012 5:56:09 PM CST> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID "1330682169014" for task "2". Error is: "weblogic.application.ModuleException: [HTTP:101216]Servlet: "AddServletServlet" failed to preload on startup in Web application: "DynamicAddServlet". 
java.lang.UnsupportedOperationException: [HTTP:101388]The ServletContext was passed to the ServletContextListener.contextInitialized method of a ServletContextListener that was neither declared in web.xml or web-fragment.xml, nor annotated with javax.servlet.annotation.WebListener. 
    at weblogic.servlet.internal.WebAppServletContext.checkNotifyDynamicContext(WebAppServletContext.java:3834) 
    at weblogic.servlet.internal.WebAppServletContext.addServlet(WebAppServletContext.java:3464) 
    at weblogic.servlet.internal.WebAppServletContext.addServlet(WebAppServletContext.java:3564) 
    at test.servlets.AddServletServlet.init(AddServletServlet.java:25) 
    at javax.servlet.GenericServlet.init(GenericServlet.java:240) 
    at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:299) 
    at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:250) 
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) 
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) 
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57) 
    at weblogic.servlet.internal.StubSecurityHelper.initServletInstance(StubSecurityHelper.java:94) 
    at weblogic.servlet.internal.StubSecurityHelper.createServlet(StubSecurityHelper.java:82) 
    at weblogic.servlet.internal.StubLifecycleHelper.createOneInstance(StubLifecycleHelper.java:74) 
    at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:60) 
    at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:34) 
    at weblogic.servlet.internal.ServletStubImpl.initStubLifecycleHelper(ServletStubImpl.java:638) 
    at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:579) 
    at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:1874) 
    at weblogic.servlet.internal.WebAppServletContext.loadServletsOnStartup(WebAppServletContext.java:1848) 
    at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1738) 
    at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2740) 
    at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1704) 
    at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:781) 
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:213) 
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:208) 
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:35) 
    at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:70) 
    at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.java:212) 
    at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:111) 
    at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124) 
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:213) 
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:208) 
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:35) 
    at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:70) 
    at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:24) 
    at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:729) 
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:35) 
    at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:258) 
    at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:61) 
    at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:165) 
    at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:79) 
    at weblogic.deploy.internal.targetserver.operations.AbstractOperation.activate(AbstractOperation.java:582) 
    at weblogic.deploy.internal.targetserver.operations.ActivateOperation.activateDeployment(ActivateOperation.java:148) 
    at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doCommit(ActivateOperation.java:114) 
    at weblogic.deploy.internal.targetserver.operations.StartOperation.doCommit(StartOperation.java:149) 
    at weblogic.deploy.internal.targetserver.operations.AbstractOperation.commit(AbstractOperation.java:335) 
    at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentCommit(DeploymentManager.java:844) 
    at weblogic.deploy.internal.targetserver.DeploymentManager.activateDeploymentList(DeploymentManager.java:1253) 
    at weblogic.deploy.internal.targetserver.DeploymentManager.handleCommit(DeploymentManager.java:440) 
    at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.commit(DeploymentServiceDispatcher.java:163) 
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doCommitCallback(DeploymentReceiverCallbackDeliverer.java:195) 
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$100(DeploymentReceiverCallbackDeliverer.java:13) 
    at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$2.run(DeploymentReceiverCallbackDeliverer.java:68) 
    at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:545) 
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256) 
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)" 

由於提前,

河馬

回答

1

根據Servlet規範(點4.4),則只能從一個ServletContextListener實施contextInitialized方法或從ServletContainerInitializer實施onStartup方法執行方法addServlet

Servlet Specification

+0

感謝,還發現另一個線程: http://stackoverflow.com/questions/4490648/adding-a-dynamic-servlet-using-servlet-3-0-throws-exception – Hippo 2012-03-07 03:39:15

相關問題