小编J88*_*888的帖子

如何在java中找到两个日期之间的差异持续时间?

我有两个DateTime对象,需要找到它们的差异持续时间,

我有以下代码,但不知道如何继续它以获得预期的结果如下:

      11/03/14 09:30:58
      11/03/14 09:33:43
      elapsed time is 02 minutes and 45 seconds
      -----------------------------------------------------
      11/03/14 09:30:58 
      11/03/15 09:30:58
      elapsed time is a day
      -----------------------------------------------------
      11/03/14 09:30:58 
      11/03/16 09:30:58
      elapsed time is two days
      -----------------------------------------------------
      11/03/14 09:30:58 
      11/03/16 09:35:58
      elapsed time is two days and 05 mintues
Run Code Online (Sandbox Code Playgroud)

    String dateStart = "11/03/14 09:29:58";
    String dateStop = "11/03/14 09:33:43";

    Custom date format
    SimpleDateFormat format = new SimpleDateFormat("yy/MM/dd HH:mm:ss");

    Date d1 = null;
    Date d2 = null; …
Run Code Online (Sandbox Code Playgroud)

java date-arithmetic

101
推荐指数
9
解决办法
33万
查看次数

不推荐使用FilterDispatcher! - FilterDispatcher的替代品是什么?

如何避免以下错误?我正在Struts2上实现Spring-Security,应用程序运行完美,但以下消息将显示在服务器日志中.

 WARNING!!!                            
 FilterDispatcher <<< is deprecated! Please use the new filters!                                                                      
      This can be a source of unpredictable problems!                                                                  
         Please refer to the docs for more details!                           
         http://struts.apache.org/2.x/docs/webxml.html            
Run Code Online (Sandbox Code Playgroud)

struts2

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

如何向不同的Web服务发送多个异步请求?

我需要向多个不同的Web服务发送多个请求并接收结果.问题是,如果我逐个发送请求,只要我需要单独发送和处理所有请求.

我想知道如何立即发送所有请求并收到结果.

如下面的代码所示,我有三个主要方法,每个方法都有自己的子方法.每个子方法向其关联的Web服务发送请求并接收结果;因此,例如,为了接收Web服务9的结果,我必须等到1到8的所有Web服务都完成,这需要很长时间才能发送所有请求一个接一个,并收到他们的结果.

如下所示,没有任何方法或子方法彼此相关,所以我可以将它们全部调用并以任何顺序接收它们的结果,唯一重要的是接收每个子方法的结果并填充它们相关列表.

private List<StudentsResults> studentsResults = new ArrayList();
private List<DoctorsResults> doctorsResults = new ArrayList();
private List<PatientsResults> patientsResults = new ArrayList();

main (){
    retrieveAllLists();
}

retrieveAllLists(){

     retrieveStudents();
     retrieveDoctors();
     retrievePatients();
}

retrieveStudents(){

    this.studentsResults = retrieveStdWS1();   //send request to Web Service 1 to receive its  list of students
    this.studentsResults = retrieveStdWS2();  //send request to Web Service 2 to receive its  list of students
    this.studentsResults = retrieveStdWS3(); //send request to Web Service 3 to receive its  list of students

}

retrieveDoctors(){

   this.doctorsResults …
Run Code Online (Sandbox Code Playgroud)

java web-services soap-client java-ee rest-client

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

如何解读分析结果?

我使用NetBeans和VisualVM运行内存Profiler并收到了结果但是没有线索如何分析其结果,我研究了这篇文章,但它没有教导或提供如何解释结果的线索.

我还发现了这篇关于在Netbeans 4上解释结果的文章,但我正在寻找一篇包含更多细节的文章,或者是一种解释以下结果的方法.

在此输入图像描述

java profiler visualvm performance-testing netbeans-7

11
推荐指数
3
解决办法
2426
查看次数

一次将多个文件上传到Struts2 @Action

我需要使用Struts2一次上传"1000个文件"或"包含所有文件的zip文件".(通过1000个文件或一个zip文件,我的意思是我需要在系统上传所有文件,如果用户一次选择所有1000个文件或者压缩它们并上传为单个文件,那么我无需重要,所以我正在寻找更容易实现和更有效的那个)

我已经阅读了以下答案,但它们都不符合目的.

使用下面的代码,当我使用一个简单的List文件时; 它显示了列表的名称,但是当我使用List文件时它没有显示任何内容,我无法上传文件.

upload.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <form action="upload" enctype="multipart/form-data" method="post">
            <input name="files" type="file" multiple/>
            <button type="submit"/>
        </form>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

upload.java

@Action
public class upload implements Addresses {

    private List <File> files = new ArrayList <File> ();

    public String execute(){

        return "success";
    }
    public upload() {
        System.out.println("in upload 1");

         for(int i=0;i<files.size();i++)
            System.out.println(i + ")" + files.get(i));

        System.out.println("in upload 2");
    }

    public List <File> getFiles() …
Run Code Online (Sandbox Code Playgroud)

jsp struts2 file-upload

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

如何从服务器向客户端发送消息?

我将实现类似于Facebook通知和本网站的内容(StackOverflow的通知,如果有人为我们的问题撰写评论/答案等,则通知我们).请注意,用户将使用我的应用程序作为网站而不是移动应用程序.

我遇到了以下获取结果的答案,但我需要推送结果而不是获取.

根据建议,我在我的实体类中创建了一个简单的方法并添加了@PostPersist但它没有工作,基于这个答案我添加了persistence.xml文件来定义监听器但是在session.save(user)之后aftersave方法不会被触发.

User.java

@Entity
public class User{
  .....
  @PostPersist
    public void aftersave(){
        System.err.println("*****this is post persist method****");
    }
}
Run Code Online (Sandbox Code Playgroud)

persistence.xml中

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->

<property name="hibernate.ejb.event.pre-insert"  value="my.hibernate.events.listeners.Listener" />
<property name="hibernate.ejb.event.pre-update"  value="my.hibernate.events.listeners.Listener" />
<property name="hibernate.ejb.event.pre-delete"  value="my.hibernate.events.listeners.Listener" />
<property name="hibernate.ejb.event.post-insert" value="my.hibernate.events.listeners.Listener" />
<property name="hibernate.ejb.event.post-update" value="my.hibernate.events.listeners.Listener" />
<property name="hibernate.ejb.event.post-delete" value="my.hibernate.events.listeners.Listener" />
Run Code Online (Sandbox Code Playgroud)

的pom.xml

 <dependency>
            <groupId>org.hibernate</groupId> …
Run Code Online (Sandbox Code Playgroud)

mysql notifications hibernate struts2 java-ee

9
推荐指数
1
解决办法
2616
查看次数

如何使用java创建oAuth请求?

我需要使用oAuth 与Viagogo网站建立联系.参考他们的文档,我需要创建一个类似于下面的请求

Using the example in step 1A, this means you may generate a signature base string that looks like the following:

GET&http%3A%2F%2Fapi.viagogo.net%2FPublic%2FSimpleOAuthAccessRequest&oauth_consumer_key%3Dtestkey%26oauth_nonce%3Dmyn0nc3%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1292404912%26oauth_version%3D1.0%26scope%3DAPI.Public
Run Code Online (Sandbox Code Playgroud)

我正在使用以下代码,但是当我对第1,2行进行注释时,它会返回未经授权的错误,当我使用它们时,它会显示oauthService.signRequest返回void.

TradeKingAPI.java

import org.scribe.builder.api.DefaultApi10a;
import org.scribe.model.Token;

public class TradeKingAPI extends DefaultApi10a {
    @Override
    public String getRequestTokenEndpoint() {
        return "http://api.viagogo.net/Public/SimpleOAuthAccessRequest";
    }
    @Override
    public String getAccessTokenEndpoint() {
        return "http://api.viagogo.net/Public/SimpleOAuthAccessRequest";
    }
    @Override
    public String getAuthorizationUrl(Token requestToken) {
        return "http://api.viagogo.net/Public/SimpleOAuthAccessRequest";
    }
}
Run Code Online (Sandbox Code Playgroud)

main.java

import org.scribe.builder.ServiceBuilder;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Response;
import org.scribe.model.Token;
import org.scribe.model.Verb; …
Run Code Online (Sandbox Code Playgroud)

java oauth java-ee scribe oauth-2.0

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

如何将不同记录的数据添加到单个记录中?

如果没有时间,请看一下这个例子

我有两种类型的用户,临时用户和永久用户.

临时用户使用系统作为访客只需提供他们的名字并使用它,但系统需要跟踪它们.

永久用户是那些已注册且永久的用户.

一旦用户为自己创建永久记录,我需要将用户作为访客时被跟踪的所有信息复制到他的永久记录中.

课程如下,

@Entity
public class PermUser{
    @Id
    @GeneratedValue
    private long id;

    @OneToMany
    private List Favorites favorites;    
    ....

}

@Entity
public class Favorites {
    @Id
    @GeneratedValue
    private long id;

    @OneToMany (cascade = CascadeType.ALL)
    @LazyCollection(LazyCollectionOption.FALSE)
    private List <FavoriteItems> items;

    ...
 }

 @Entity
   public class FavoriteItems {
     @Id
     @GeneratedValue
     private long id;

     private int quantity;

     @ManyToOne
     private Ball ball;
     ..
   }


@Entity
public class TempUser extends PermUser{
    private String date;
    ....
}
Run Code Online (Sandbox Code Playgroud)

问题是:

如果我克隆tempUser对象,我也会复制id参数,所以当保存perm用户对象时,它会显示一条消息,如"密钥条目'10'为密钥...",我无法先删除tempUser然后保存permUser就像保存permUser失败一样,我将错过数据.如果我尝试单独复制每个最喜欢的球项而没有项目ID,那么这将不是一种有效的方法.

示例(一句话中的问题:如图所示,用户可能有多个TempUser记录和一个PermUser记录,因此我需要将所有TempUser记录的信息添加到该单个PermUser记录中.)

  Type of …
Run Code Online (Sandbox Code Playgroud)

java hibernate hibernate-mapping java-ee

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

如何在网站上使用iPad相机阅读二维码?

我使用以下代码访问相机,但目的是使用相机读取QR码.使用下面的代码,我只能拍照并保存,然后使用我的后端从保存的文件中读取QR码.

如何在相机读取时修改代码以处理图片.或者类似于将流发送到后端并且一旦检测到QR码就通知用户.

我需要使用平板电脑.

我也可以使用以下内容来录制视频,但如何将流发送到后端

 <input type="file" capture="camera" accept="video/*">
Run Code Online (Sandbox Code Playgroud)

我的代码拍照

<!DOCTYPE HTML>
<html>
    <head>
    <meta name="viewport" content="width=320; user-scalable=no" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <title>ColorThief Demo</title>

    <script type="text/javascript" charset="utf-8" src="jquery-2.0.0.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="quantize.js"></script>
    <script type="text/javascript" charset="utf-8" src="color-thief.js"></script>

    <style>
    #yourimage {
        width:100%; 
    }

    #swatches {
        width: 100%;
        height: 50px;   
    }

    .swatch {
        width:18%;
        height: 50px;
        border-style:solid;
        border-width:thin;  
        float: left;
        margin-right: 3px;  
    }
    </style>
    </head>

    <body>

        <input type="file" capture="camera" accept="image/*" id="takePictureField">
        <img id="yourimage">

        <div id="swatches">
            <div id="swatch0" class="swatch"></div>
            <div id="swatch1" class="swatch"></div>
            <div id="swatch2" …
Run Code Online (Sandbox Code Playgroud)

javascript jquery qr-code java-ee zxing

7
推荐指数
1
解决办法
8070
查看次数

我的用户访问方式是否正确?

我在我的jsp页面上应用spring security,我需要向具有不同角色的用户显示页面的不同部分,所有角色如下.

所有经过身份验证的用户>>编辑和添加新

管理>删除和编辑并添加新

匿名>添加新

<sec:authorize
        access="isAuthenticated()">
          Code of add new and edit buttons
 </sec:authorize>

 <sec:authorize 
         access="hasAnyRole('ADMIN')">
   Code to add new, edit and delete buttons
 </sec:authorize>

  <sec:authorize 
         access="isAnonymous()">
     Code to add new
  </sec:authorize>
Run Code Online (Sandbox Code Playgroud)

我想知道是否有更简单的方法,在这种情况下,如果我想修改特定角色的访问权限,我必须更改其在security.xml文件中的访问规则以及我已设置角色访问权限的每个页面.

例如,假设我想要Admin角色无法访问删除按钮,那么我必须更改security.xml的代码以及admin角色经过身份验证的所有JSP页面以查看删除按钮.

有没有更简单的方法来做到这一点!?

spring-security

5
推荐指数
1
解决办法
579
查看次数