小编far*_*eed的帖子

为什么这两个乘法运算会得到不同的结果?

为什么我需要添加"L"字母才能获得正确的长值?另一个价值是什么?

long oneYearWithL = 1000*60*60*24*365L;
long oneYearWithoutL = 1000*60*60*24*365;
System.out.println(oneYearWithL);//gives correct calculation result : 31536000000
System.out.println(oneYearWithoutL)//gives incorrect calculation result: 1471228928
Run Code Online (Sandbox Code Playgroud)

java int operation multiplication long-integer

37
推荐指数
2
解决办法
5408
查看次数

graphicimage在Primefaces中不渲染流式内容

我正在使用streamedcontent渲染从JSF发送的字节,然后将其作为流内容发送回如下:

<p:graphicImage value="#{manage.bytesToStreamedContent(car.image)}"/>
Run Code Online (Sandbox Code Playgroud)

其中image是存储在数据库中的图像的字节数组

支持豆:

public StreamedContent bytesToStreamedContent(byte[] bytes)
{
    InputStream is = new ByteArrayInputStream(bytes);
    StreamedContent image = new DefaultStreamedContent (is, "image/jpeg");
    return image;
}
Run Code Online (Sandbox Code Playgroud)

但我没有在JSF页面中获取图像.我在服务器日志中显示此消息:

警告:JSF1091:找不到文件dynamiccontent的mime类型.要解决此问题,请将mime类型映射添加到应用程序web.xml.

和:

SEVERE: Error in streaming dynamic resource.
Run Code Online (Sandbox Code Playgroud)

你可以帮帮我吗,我找不到有关这个问题的任何有用的信息

PS:

我使用以下库:

Mojarra 2.1.3

PrimeFaces 3.1.1

Glassfish 3.1

primefaces jsf-2

11
推荐指数
1
解决办法
2万
查看次数

警告:来自public void org.omnifaces.cdi.eager.EagerBeansRepository.setXxx的List <Bean <?>>类型的参数1无法解析为具体类型

我正在使用Omnifaces 1.8.1,每当我将我的应用程序部署到Glassfish时,我都会收到以下警告,这会导致部署过程出现延迟.

Warning:   WELD-001519 An InjectionTarget implementation is created for an abstract class org.omnifaces.eventlistener.DefaultHttpSessionListener. It will not be possible to produce instances of this type!
Warning:   WELD-001519 An InjectionTarget implementation is created for an abstract class org.omnifaces.eventlistener.DefaultServletContextListener. It will not be possible to produce instances of this type!
Warning:   WELD-001519 An InjectionTarget implementation is created for an abstract class org.omnifaces.eventlistener.DefaultServletRequestListener. It will not be possible to produce instances of this type!
Warning:   WELD-001519 An InjectionTarget implementation is created for an …
Run Code Online (Sandbox Code Playgroud)

jsf glassfish cdi omnifaces weld

8
推荐指数
1
解决办法
2872
查看次数

创建Glassfish Windows服务错误

我在窗口创建了glassfish服务但无法启动服务.我检查了域服务错误日志并收到以下错误:

Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.8', but '1.7' is required. 
could not find java.dll
Could not find Java SE Runtime Environment.
Run Code Online (Sandbox Code Playgroud)

我已经从Java 7升级到Java 8,升级服务后无法启动.我怎样才能解决这个问题

windows-services glassfish

4
推荐指数
1
解决办法
712
查看次数

WELD-001409类型[EagerBeansRepository]的模棱两可的依赖项

我正在尝试将JSF应用程序迁移到CDI。我已作出以下更改:

  • 向WEB-INF添加了一个空bean.xml文件
  • 将@ManagedBean的更改为@Named
  • 将我必须拥有的所有范围更改为CDI范围(会话,视图,请求)
  • 将所有@EJB和@ManagedProperty更改为@Inject

但是,Omnifaces错误阻止了部署,因为我三次遇到以下错误:

org.jboss.weld.exceptions.DeploymentException:WELD-001409类型[EagerBeansRepository]的模棱两可的依赖项,在注入点[[BackedAnnotatedField] @Inject私有org.omnifaces.ApplicationListener.eagerBeansRepository]上带有限定符[@Default]。可能的依赖关系[[带限定符[@Any @Default的托管Bean [类org.omnifaces.cdi.eager.EagerBeansRepository]],带限定符[@Any @Default的托管Bean [类org.omnifaces.cdi.eager.EagerBeansRepository]] ]

我已降级为Omnifaces 1.8.1,并且部署成功。为什么Omnifaces 2.0导致此错误?

开发环境:

  • 玻璃鱼4
  • Omnifaces 2.0
  • JSF(Mojarra 2.2.0)
  • WELD-000900 2.0.0(SP1)

jsf glassfish cdi omnifaces weld

4
推荐指数
1
解决办法
3501
查看次数

How to get returning ID in JPA after native query insert

I have the following code in JPA to return an auto generated ID after inserting using native query:

Query q = em.createNativeQuery("insert into .... returning ID", Long.class);
q.executeUpdate();
Run Code Online (Sandbox Code Playgroud)

However, I'm getting the following error:

A result was returned when none was expected
Run Code Online (Sandbox Code Playgroud)

postgresql hibernate jpa

4
推荐指数
1
解决办法
3938
查看次数

JSF Cryptojacking恶意软件

现在我知道这不是安全或恶意软件删除网站.但是我觉得这是一个JSF特定的问题,

我注意到我的网站不断受到攻击,只是将一个JavaScript文件注入网页.

恶意软件正在从一些具有以下模式的随机URL加载脚本文件:https://johndi33.*****.***:7777/deepMiner.js.

在重新部署应用程序时会删除恶意软件,但是在几个小时后,重新启动攻击并注入脚本.

在对这种特定的加密劫持恶意软件进行一些研究后,我发现有数百或数千个具有相同恶意软件的受感染网站,我还注意到所有受感染的网站都是基于JSF的.

我想知道是否有任何关于这个或任何可以轻松导致RCE的JSF错误配置的意识.

PS - 环境:

  • Ubuntu 16.04

  • Wildfly 10.1

  • Java 8

security jsf cryptojacking

4
推荐指数
1
解决办法
1020
查看次数

通过最接近x的值对对象数组进行排序

我有一个对象数组,我想通过最接近X的值对该数组进行排序.

例如,这是一个对象数组:

[
 {"name" : "some 1", "value" : 12.4},
 {"name" : "some 2", "value": 11.4},
 {"name" : "some 3", "value": 10.5},
 {"name" : "some 4", "value": 11.4}
]
Run Code Online (Sandbox Code Playgroud)

我想通过最接近X的"值"对其进行排序.

假设我想对数组进行排序,使属性"value"最接近11.所以新的顺序如下:

[
  {"name" : "some 2", "value": 11.4},
  {"name" : "some 4", "value": 11.4},
  {"name" : "some 3", "value": 10.5},
  {"name" : "some 1", "value": 12.4}
 ]
Run Code Online (Sandbox Code Playgroud)

因为11.4最接近11,然后是10.5然后是12.4.

javascript arrays sorting

4
推荐指数
1
解决办法
55
查看次数

如何使用JDBCRealm获取登录用户的用户名?

我正在运行Glassfish 3.0,我正在实现JDBCRealm用于登录身份验证.用户名和角色保存在名为usertable的表中.身份验证按预期工作.

但问题是,当用户登录时,如何在应用程序中检索登录用户的用户名?

PS:我正在实现JSF页面和Managed Bean

java jsf login j-security-check managed-bean

3
推荐指数
1
解决办法
6717
查看次数

iText直接打印

我正在使用iText生成pdf并将其写入文件系统,如下所示:

private void createPDF() throws Exception{
    com.itextpdf.text.Document doc = new com.itextpdf.text.Document();
    PdfWriter docWriter = null;
    path = "C:\\PATH\\TO\\Desktop\\EXAMPLE_FOLDER\\" + pdfFilename;
    docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path));
    doc.addTitle("Invoice");
    doc.setPageSize(PageSize.A4);
    doc.open();
    PdfContentByte cb = docWriter.getDirectContent();
    fillPDFDetails(cb);
    if (doc != null) {
        doc.close();
    }
    if (docWriter != null) {
        docWriter.close();
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我想将pdf发送到打印机并打印pdf文件,而不是将其写入文件系统.我怎样才能做到这一点?

java printing pdf itext

3
推荐指数
1
解决办法
1万
查看次数