- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
JSP 和 html 文件由我在 NetBeans 中的 Glassfish 服务器提供,但不是 servlet。最新的 NetBeans 配置为使用最新的 JDK 13,而 Glassfish 使用的是 Java EE 1.8
浏览器报错:
HTTP Status 500 - Internal Server Error
type Exception report
message
Internal Server Error
description
The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Error instantiating servlet class com.example.NewServlet
root cause
com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class com.example.NewServlet
root cause
java.lang.RuntimeException:
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 5.1.0 logs.
服务器报错(注意它总是在 sevlet 类的第 1 行!这是通常声明 package
的地方):
StandardWrapperValve[NewServlet]: Allocate exception for servlet NewServlet
java.lang.RuntimeException:
at com.example.NewServlet.<init>(NewServlet.java:1)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:119)
at org.jboss.weld.injection.ConstructorInjectionPoint.invokeAroundConstructCallbacks(ConstructorInjectionPoint.java:92)
at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:78)
at org.jboss.weld.injection.producer.AbstractInstantiator.newInstance(AbstractInstantiator.java:28)
at org.jboss.weld.injection.producer.BasicInjectionTarget.produce(BasicInjectionTarget.java:112)
at org.jboss.weld.injection.producer.BeanInjectionTarget.produce(BeanInjectionTarget.java:180)
at org.glassfish.weld.services.JCDIServiceImpl.createManagedObject(JCDIServiceImpl.java:435)
at org.glassfish.weld.services.JCDIServiceImpl.createManagedObject(JCDIServiceImpl.java:293)
at com.sun.enterprise.container.common.impl.managedbean.ManagedBeanManagerImpl.createManagedBean(ManagedBeanManagerImpl.java:453)
at com.sun.enterprise.container.common.impl.managedbean.ManagedBeanManagerImpl.createManagedBean(ManagedBeanManagerImpl.java:406)
at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.createManagedObject(InjectionManagerImpl.java:312)
at com.sun.enterprise.web.WebContainer.createServletInstance(WebContainer.java:725)
at com.sun.enterprise.web.WebModule.createServletInstance(WebModule.java:1955)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1262)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1069)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:119)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:550)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:75)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:114)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:199)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:439)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:144)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:515)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
at java.lang.Thread.run(Thread.java:748)
Netbeans 生成的未修改的 servlet shell:
public class NewServlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try ( PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet NewServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
查看一个模糊相似的帖子的解决方案,还尝试添加一个无参数构造函数:
public NewServlet() {
super();
}
Glassfish 初创公司的恶作剧:
Launching GlassFish on Felix platform
INFO: Create bundle provisioner class = class com.sun.enterprise.glassfish.bootstrap.osgi.BundleProvisioner.
WARNING: Skipping entry because it is not an absolute URI.
WARNING: Skipping entry because it is not an absolute URI.
Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishRuntime@3b4af5 in service registry.
#!## LogManagerService.postConstruct : rootFolder=D:\GlassfishDownload\glassfish
#!## LogManagerService.postConstruct : templateDir=D:\GlassfishDownload\glassfish\lib\templates
#!## LogManagerService.postConstruct : src=D:\GlassfishDownload\glassfish\lib\templates\logging.properties
#!## LogManagerService.postConstruct : dest=D:\GlassfishDownload\glassfish\domains\domain1\config\logging.properties
Running GlassFish Version: GlassFish Server Open Source Edition 5.1.0 (build default-private)|#]
Server log file is using Formatter class: com.sun.enterprise.server.logging.ODLLogFormatter|#]
Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.|#]
Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.|#]
Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.|#]
Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry|#]
Authorization Service has successfully initialized.|#]
JTS5014: Recoverable JTS instance, serverId = [100]|#]
Grizzly Framework 2.4.4 started in: 81ms - bound to [/0.0.0.0:8080]|#]
Grizzly Framework 2.4.4 started in: 5ms - bound to [/0.0.0.0:8181]|#]
Grizzly Framework 2.4.4 started in: 5ms - bound to [/0.0.0.0:4848]|#]
Grizzly Framework 2.4.4 started in: 5ms - bound to [/0.0.0.0:3700]|#]
visiting unvisited references|#]
HV000001: Hibernate Validator 6.0.10.Final|#]
Grizzly Framework 2.4.4 started in: 6ms - bound to [/0.0.0.0:8080]|#]
Grizzly Framework 2.4.4 started in: 7ms - bound to [/0.0.0.0:8181]|#]
Java security manager is disabled.|#]
Entering Security Startup Service.|#]
Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.|#]
Security Service(s) started successfully.|#]
Created HTTP listener http-listener-1 on host/port 0.0.0.0:8080|#]
Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181|#]
Created HTTP listener admin-listener on host/port 0.0.0.0:4848|#]
Created virtual server server|#]
Created virtual server __asadmin|#]
Setting JAAS app name glassfish-web|#]
Virtual server server loaded default web module |#]
visiting unvisited references|#]
visiting unvisited references|#]
visiting unvisited references|#]
visiting unvisited references|#]
WELD-000900: 3.0.0 (Final)|#]
WELD-000411: Observer method [BackedAnnotatedMethod] public org.hibernate.validator.cdi.ValidationExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
Listening to REST requests at context: /management/domain.|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.ibm.jbatch.container.cdi.BatchProducerBean is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.WebAppExceptionHolder is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.WebAppExceptionInterceptor is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.TransactionalExceptionMapper is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider$JaxRsParamProducer is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.sun.faces.flow.FlowDiscoveryCDIHelper is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorMandatory is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorNever is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorNotSupported is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorRequired is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorRequiresNew is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorSupports is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.servlet.internal.CdiExternalRequestScope is deprecated from CDI 1.1!|#]
Initializing Soteria 1.0.1 for context '/BackToTech'|#]
Initializing Mojarra 2.3.9 for context '/BackToTech'|#]
Loading application [BackToTech] at [/BackToTech]|#]
Loading application BackToTech done in 17,036 ms|#]
GlassFish Server Open Source Edition 5.1.0 (default-private) startup time : Felix (9,720ms), startup services(18,529ms), total(28,249ms)|#]
Grizzly Framework 2.4.4 started in: 21ms - bound to [/0.0.0.0:7676]|#]
visiting unvisited references|#]
Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishImpl@b224cd as OSGi service registration: org.apache.felix.framework.ServiceRegistrationImpl@1ee25f1.|#]
JMXStartupService has started JMXConnector on JMXService URL service:jmx:rmi://DESKTOP-2IGRR7A:8686/jndi/rmi://DESKTOP-2IGRR7A:8686/jmxrmi|#]
Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181|#]
Grizzly Framework 2.4.4 started in: 7ms - bound to [/0.0.0.0:8181]|#]
Created HTTP listener http-listener-1 on host/port 0.0.0.0:8080|#]
Grizzly Framework 2.4.4 started in: 13ms - bound to [/0.0.0.0:8080]|#]
visiting unvisited references|#]
visiting unvisited references|#]
visiting unvisited references|#]
visiting unvisited references|#]
visiting unvisited references|#]
visiting unvisited references|#]
visiting unvisited references|#]
visiting unvisited references|#]
WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
WELD-000411: Observer method [BackedAnnotatedMethod] public org.hibernate.validator.cdi.ValidationExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorMandatory is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorNever is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorNotSupported is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorRequired is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorRequiresNew is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorSupports is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.ibm.jbatch.container.cdi.BatchProducerBean is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.WebAppExceptionHolder is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.WebAppExceptionInterceptor is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.TransactionalExceptionMapper is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider$JaxRsParamProducer is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.sun.faces.flow.FlowDiscoveryCDIHelper is deprecated from CDI 1.1!|#]
WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.servlet.internal.CdiExternalRequestScope is deprecated from CDI 1.1!|#]
最佳答案
假设“Latest NetBeans”指的是 NetBeans 11.2,Glassfish 问题是由使用 JDK 13 运行 NetBeans 引起的。这种方法没有直接的错误;从 NetBeans 11.2 开始明确支持它。
但是,这意味着当您在 NetBeans 中启动 Glassfish 5 服务器时,它也将使用 Java 13。请参阅 NetBeans 错误报告 NETBEANS-2256NetBeans 11 vc3: Unable to manage GlassFish 5.1 when running NetBeans using any JDK greater than JDK 8其中指出:
If I run Apache NetBeans using JDK 9+, then I am unable to manage GlassFish server or deployments to GlassFish server from within the IDE. GlassFish 5+ currently only supports JDK 8...
此问题不仅限于 NetBeans IDE。例如,参见 Eclipse Glassfish/Payara does not recognize my JDK .
您的选择是:
关于servlets - @WebServlet 在 GlassFish 5 + JDK 13 中失败,java.lang.RuntimeException : com. example.NewServlet.<init>(NewServlet.java :1), 总是在第 1 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60493004/
某种噩梦 - 无法通过使用 servlet 注释在 Apache Tomcat 9.0.22(或 Glassfish 5.0.1)和 Apache NetBeans IDE 11.0(Build in
JSP 和 html 文件由我在 NetBeans 中的 Glassfish 服务器提供,但不是 servlet。最新的 NetBeans 配置为使用最新的 JDK 13,而 Glassfish 使用
我正在考虑使用 servlet 3.0+ 容器中可用的“@Resource String ...”注入(inject)来轻松地为 servlet 提供配置参数。如果 JNDI 中不存在该 key (表
我是一名优秀的程序员,十分优秀!