来自Java Web应用程序的数据未传递到Glassfish服务器

问题描述

我不熟悉Java进行Web开发,并且正在学习使用Java进行Web应用程序的课程。 我一直在尝试获取用于正常运行的软件套件,但无法做到这一点。我们的第一个示例Java脚本使用时间函数来获取当前日期时间:

package managed_bean;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;

@Named(value = "timeUtility")
@RequestScoped
public class TimeUtility {
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
    
    public String getCurrentTime(){
        return sdf.format(Calendar.getInstance().getTime());
    }
}

然后将时间传递到Glassfish服务器,并在.xhtml文件中将其输出如下:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Simple Example</title>
    </h:head>
    <h:body>
        <h1>Simple Date Example</h1>
        <h2>Current Time:
            <h:outputText value="#{timeUtility.currentTime}" />
        </h2>
    </h:body>
</html>

但是在浏览器中我只能看到:

enter image description here

Glassfish服务器的Netbeans日志输出

OpenJDK 64-Bit Server VM warning: ignoring option MaxPermSize=192m; support was removed in 8.0
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@73cd30dc in service registry.
#!## LogManagerService.postconstruct : rootFolder=/home/alex/GlassFish_Server/glassfish
#!## LogManagerService.postconstruct : templateDir=/home/alex/GlassFish_Server/glassfish/lib/templates
#!## LogManagerService.postconstruct : src=/home/alex/GlassFish_Server/glassfish/lib/templates/logging.properties
#!## LogManagerService.postconstruct : dest=/home/alex/GlassFish_Server/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: 22ms - bound to [/0.0.0.0:8080]|#]
  Grizzly Framework 2.4.4 started in: 0ms - bound to [/0.0.0.0:8181]|#]
  Grizzly Framework 2.4.4 started in: 1ms - bound to [/0.0.0.0:4848]|#]
  Exception while visiting WEB-INF/classes/managed_bean/TimeUtility.class of size 859
java.lang.IllegalArgumentException
    at org.glassfish.hk2.external.org.objectweb.asm.ClassReader.<init>(ClassReader.java:160)
    at org.glassfish.hk2.external.org.objectweb.asm.ClassReader.<init>(ClassReader.java:143)
    at org.glassfish.hk2.external.org.objectweb.asm.ClassReader.<init>(ClassReader.java:418)
    at org.glassfish.hk2.classmodel.reflect.Parser$5.on(Parser.java:335)
    at com.sun.enterprise.v3.server.ReadableArchiveScannerAdapter.handleEntry(ReadableArchiveScannerAdapter.java:141)
    at com.sun.enterprise.v3.server.ReadableArchiveScannerAdapter.onSelectedEntries(ReadableArchiveScannerAdapter.java:103)
    at org.glassfish.hk2.classmodel.reflect.Parser.doJob(Parser.java:321)
    at org.glassfish.hk2.classmodel.reflect.Parser.access$300(Parser.java:44)
    at org.glassfish.hk2.classmodel.reflect.Parser$3.call(Parser.java:280)
    at org.glassfish.hk2.classmodel.reflect.Parser$3.call(Parser.java:269)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
|#]
  Grizzly Framework 2.4.4 started in: 0ms - bound to [/0.0.0.0:3700]|#]
  visiting unvisited references|#]
  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|#]
  Initializing Mojarra 2.3.9 for context '/WebApplication1'|#]
  HV000001: Hibernate Validator 6.0.10.Final|#]
  Loading application [WebApplication1] at [/WebApplication1]|#]
  Loading application WebApplication1 done in 2,566 ms|#]
  GlassFish Server Open Source Edition  5.1.0  (default-private) startup time : Felix (2,090ms),startup services(2,969ms),total(5,059ms)|#]
  Grizzly Framework 2.4.4 started in: 1ms - bound to [/0.0.0.0:7676]|#]
  Registered com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOsgiGlassFishImpl@23ee75c5 as Osgi service registration: org.apache.Felix.framework.ServiceRegistrationImpl@11a7ba62.|#]
  visiting unvisited references|#]
  JMXStartupService has started JMXConnector on JMXService URL service:jmx:rmi://penguin:8686/jndi/rmi://penguin:8686/jmxrmi|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  visiting unvisited references|#]
  Initializing Mojarra 2.3.9 for context ''|#]
  Loading application [__admingui] at [/]|#]
  Loading application __admingui done in 1,957 ms|#]
  Listening to REST requests at context: /management/domain.|#]
  Context path from ServletContext:  differs from path from bundle: /|#]
  Created HTTP listener http-listener-2 on host/port 0.0.0.0:8181|#]
  Grizzly Framework 2.4.4 started in: 3ms - 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: 8ms - bound to [/0.0.0.0:8080]|#]

使用的环境和软件:

  1. 操作系统:Ubuntu 20 Desktop
  2. NetBeans 12
  3. Java版本8.1(1.8.0_272)
  4. Glasshfish服务器(通过netbeans IDE下载)版本4.1和5.1

其他详细信息: 有人告诉我使用Java 8.1,而不是最新版本。 我也会在Ubuntu桌面上配置全栈AMP服务器,如果这可能会造成干扰的话。 我可以通过Netbeans毫无问题地访问和使用MysqL数据库

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...