小编sfr*_*frj的帖子

如何操作.doc文件

我需要在Java中创建一个小桌面应用程序,它为我创建一个.doc文件并将一些文本写入文件.我发现了一个名为Aspose的有趣工具,但我发现它根本不是免费的.你是否知道我可以使用哪种java API(免费)?是否有可能只使用java SE库?您认为实现这一目标的最简单,最快捷的方法是什么?

java doc

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

javamail将图像添加到html电子邮件中.怎么样?

我正在发送带有javamail的电子邮件没有问题(我使用EJB 3.0),问题是当我尝试通过使用多部分方法将一些图像添加到html时.出于某种原因,我得到一个FileNotFoundException.我不知道如何获取位于WEB-INF/resources/images的.png图像的路径.

这是我做的:

Message message = new MimeMessage(mailSession);
        // From: is our service
        message.setFrom(new InternetAddress(from));
        // To: destination given
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse(to));
        message.setSubject("Uspijesna registracija");
        // How to found at http://www.rgagnon.com/javadetails/java-0321.html
        message.setContent(generateActivationLinkTemplate(), "text/html");

        Date timeStamp = new Date();
        message.setSentDate(timeStamp);

        // Prepare a multipart HTML
        Multipart multipart = new MimeMultipart("related");
        // Prepare the HTML
        BodyPart htmlPart = new MimeBodyPart();
        htmlPart.setContent(generateActivationLinkTemplate(), "text/html");
        multipart.addBodyPart(htmlPart);
        // PREPARE THE IMAGE
        BodyPart imgPart = new MimeBodyPart();
        DataSource ds = new FileDataSource("logomailtemplate.png");
        imgPart.setDataHandler(new DataHandler(ds));
        imgPart.setHeader("Content-ID", "the-img-1");
        multipart.addBodyPart(imgPart);
        // Set …
Run Code Online (Sandbox Code Playgroud)

java jakarta-mail java-ee ejb-3.0 java-ee-6

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

无法通过classLoader.getResourceAsStream()从WEB-INF文件夹中检索图像

中午我试图让我的应用程序通过javamail发送html +图像,我只设法发送html,但与图像我有一些问题.我决定创建一个多部分消息,一切顺利,但后来我使用类加载器从WEB-INF/resources/images检索.png文件我得到一个NullPointerExcetion,我不知道为什么会这样?

这是我的EJB(3.0)的样子.我很欣赏这一个我没有太多经验的ClassLoader类(不太了解它).

@Stateless(name = "ejbs/EmailServiceEJB")
public class EmailServiceEJB implements IEmailServiceEJB {

@Resource(name = "mail/myMailSession")
private Session mailSession;

public void sendAccountActivationLinkToBuyer(String destinationEmail,
        String name) {

    // Destination of the email
    String to = destinationEmail;
    String from = "dontreply2thismessage@gmail.com";

    try {
        Message message = new MimeMessage(mailSession);
        // From: is our service
        message.setFrom(new InternetAddress(from));
        // To: destination given
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse(to));
        message.setSubject("Uspijesna registracija");
        // How to found at http://www.rgagnon.com/javadetails/java-0321.html
        message.setContent(generateActivationLinkTemplate(), "text/html");

        Date timeStamp = new Date();
        message.setSentDate(timeStamp);

        // Prepare a multipart HTML
        Multipart …
Run Code Online (Sandbox Code Playgroud)

java glassfish jakarta-mail java-ee ejb-3.0

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

定期进行调整

我使用以下正则表达式来验证我的一个文本区域:

^[a-zA-Z0-9][a-zA-Z0-9 ]+$
Run Code Online (Sandbox Code Playgroud)
  • 它允许字母数字
  • 它避免了第一个空白
  • 它在第一个字符后允许空格

我应该如何修改它以允许以下字符:

  • 昏迷(,)
  • 分号(;)
  • 冒号(:)
  • 欧元符号(€)

java regex

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

我的第一个反向ajax应用程序

我想了解反向ajax,我发现了一个名为ICEPush的小工具,我认为这可能是一个很好的起点.我无法实现一个非常简单的应用程序.我正在学习本教程,但我使用的是Glassfish 3.1而不是Eclipse,而不是使用Eclipse,而是使用NetBeans 7.1

我完全按照教程中的说法完成,请参阅我的代码.这是将成为Ajax推送目标的页面:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Easy Ajax Push - Color</title>
    </h:head>

        <h:body>
            <h:dataTable value="#{messageBean.textList}" var="current">
                <h:column>
                    <h:outputText value="#{current.text}"
                                  style="color: #{current.color};"/>
                </h:column>
            </h:dataTable>

            <hr width="100%"/>

            <h:form>
                <h:panelGrid columns="4">
                    Choose a Color:
                    <h:commandButton value="Red"
                                     action="#{colorBean.chooseColor}"
                                     style="color: white; background-color: red;">
                        <f:setPropertyActionListener target="#{colorBean.color}" value="red"/>
                    </h:commandButton>
                    <h:commandButton value="Blue"
                                     action="#{colorBean.chooseColor}"
                                     style="color: white; background-color: blue;">
                        <f:setPropertyActionListener target="#{colorBean.color}" value="blue"/>
                    </h:commandButton>
                    <h:commandButton value="Green"
                                     action="#{colorBean.chooseColor}"
                                     style="color: white; background-color: green;">
                        <f:setPropertyActionListener target="#{colorBean.color}" value="green"/>
                    </h:commandButton>
                </h:panelGrid>
            </h:form>

        </h:body>

</html>
Run Code Online (Sandbox Code Playgroud)

以下是需要的2个托管bean: ColorBean.java

@ManagedBean(name="colorBean")
@ViewScoped
public class ColorBean …
Run Code Online (Sandbox Code Playgroud)

java jsf icefaces reverse-ajax java-ee

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

我的JBoss使用什么版本的HornetQ?

在较新版本的JBoss中部署我的一个应用程序时,我遇到了异常.

NoSuchMethodError:org.hornetq.api.core.management.QueueControl.getMessageCount()I

我的假设是JBoss中较新版本的HornetQ不再提供这种方法.我想知道如何找出我的JBoss中当前的hornetQ版本,以便我可以检查API文档以获得替代方法.

有什么想法/建议?

java jboss jmx hornetq

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

需要查询以检查数据库中是否已存在电子邮件(Java Persistence API)

我试图弄清楚这个方法的问题是什么,它使用JPQL来验证数据库中是否已存在电子邮件,由于某种原因它不起作用.有人可以看看吗?或者给另一个替代查询更简单?

@Override
public boolean emailAlreadyExists(String value) {
    Query checkEmailExists = em.createQuery("SELECT COUNT(b.email) FROM "
            + Buyer.class.getName() + " b WHERE email = :emailparam");
    checkEmailExists.setParameter("emailparam", value);
    long matchCounter = 0;
    matchCounter = (Long) checkEmailExists.getSingleResult();
    if (matchCounter > 0) {
        return true;
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

这是控制台输出的一部分:

引发者:异常[EclipseLink-8024](Eclipse Persistence Services - 2.0.1.v20100213-r6600):org.eclipse.persistence.exceptions.JPQLException异常描述:解析查询时出现语法错误[SELECT COUNT(b.email)FROM entities .Buyer b WHERE b.email =:emailparam],第1行,第35列:[.]处的语法错误.内部异常:MismatchedTokenException(83!= 78)

我确定它必须对语法做些什么.但是我犯了错误?

java jpa jpql java-ee java-ee-6

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

SQLSyntaxErrorException: 表/视图 'BUYER' 不存在。有什么不见了?

几周前,我去度假并暂停了我的一个项目。当我回来时,我只是在检查注册页面,当我收到 SQLException 说表不存在时,我感到很惊讶。我不明白,因为该表存在,我从一个实体创建了它。我把代码贴在这里,所以你可以看到一切似乎都没有问题。我认为这可能与数据库有关(我使用 glassfish 3 应用服务器)。

这是用户界面中的一张图片,说明问题与某些验证方法有关(检查用户是否已存在并检查电子邮件是否已存在):

在此处输入图片说明

以防万一我也会打印堆栈跟踪:

WARNING: Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Table/View 'BUYER' does not exist.
Error Code: -1
Call: SELECT COUNT(NICKNAME) FROM BUYER WHERE (NICKNAME = ?)
    bind => [test]
Query: ReportQuery(referenceClass=Buyer sql="SELECT COUNT(NICKNAME) FROM BUYER WHERE (NICKNAME = ?)")
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:687)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:530)
    at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:529)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:205)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:191)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:262)
    at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:618)
    at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2537)
    at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllReportQueryRows(ExpressionQueryMechanism.java:2480)
    at org.eclipse.persistence.queries.ReportQuery.executeDatabaseQuery(ReportQuery.java:838)
    at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:675)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:958)
    at …
Run Code Online (Sandbox Code Playgroud)

java sql orm jpa glassfish

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

通过 Spring 4 配置时,Quartz Scheduler 不会触发作业

我曾经尝试设置一个小程序,使用 Spring 和 Quartz 来安排任务。我遵循了其他一些类似的答案,但没有运气。目前我认为我已经正确配置了所有配置,我没有看到更多异常,但我的工作看起来还没有开始。

在 Spring 生成的 log.out 中,我在末尾看到以下消息:

2015-06-04T15:46:57.928调试[org.springframework.core.env.PropertySourcesPropertyResolver]在[systemProperties]中搜索键“spring.liveBeansView.mbeanDomain”2015-06-04T15:46:57.929调试[org.springframework。 core.env.PropertySourcesPropertyResolver] 在 [systemEnvironment] 2015-06-04T15:46:57.929 DEBUG [org.springframework.core.env.PropertySourcesPropertyResolver] 中搜索键“spring.liveBeansView.mbeanDomain”,找不到键“spring.liveBeansView”。任何属性源中的 mbeanDomain'。返回[空]

我会告诉你我的代码...

这是我启动调度程序的类:

public class JobRunner {

    public static void main(String[] args) throws SchedulerException {
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(WhatsTheTimeConfiguration.class);
        AutowiringSpringBeanJobFactory autowiringSpringBeanJobFactory = new AutowiringSpringBeanJobFactory();
        autowiringSpringBeanJobFactory.setApplicationContext(applicationContext);

        SpringBeanJobFactory springBeanJobFactory = new SpringBeanJobFactory();

        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        schedulerFactoryBean.setTriggers(trigger());
        schedulerFactoryBean.setJobFactory(springBeanJobFactory);
        schedulerFactoryBean.start();
    }

    private static SimpleTrigger trigger() {
        return newTrigger()
                .withIdentity("whatsTheTimeJobTrigger", "jobsGroup1")
                .startNow()
                .withSchedule(simpleSchedule()
                        .withIntervalInSeconds(1)
                        .repeatForever())
                .build();
    }

}
Run Code Online (Sandbox Code Playgroud)

我想提一下,如果我使用 SchedulerFactoryBean.getScheduler().start() 方法,它会在调度程序上引发空指针异常,这就是为什么我在工厂上调用 start() 的原因。

AutowiringSpringBeanJobFactory …

java spring quartz-scheduler

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

无法在 docker 内构建 gradle 应用程序

我正在尝试从 docker 容器内使用 gradle 构建一个应用程序。这是我的 Dockerfile:

FROM openjdk:8-jdk
#install git
RUN apt-get install -y git
RUN git clone https://github.com/SFRJ/yurl.git
#install gradle
RUN wget https://downloads.gradle-dn.com/distributions/gradle-6.5-bin.zip
RUN unzip gradle-6.5-bin.zip
ENV GRADLE_HOME /gradle-6.5
ENV PATH $PATH:/gradle-6.5/bin
#compile and run app
RUN cd yurl
RUN gradle clean build --rerun-tasks --no-build-cache
ENTRYPOINT ["java", "-jar", "/yurlapp.jar"]
Run Code Online (Sandbox Code Playgroud)

一切都很顺利,直到执行构建命令为止。它抛出以下内容:

Step 9/10 : RUN gradle clean build --rerun-tasks --no-build-cache
 ---> Running in a25d344c3571

Welcome to Gradle 6.5!

Here are the highlights of this release:
 - Experimental file-system watching
 - …
Run Code Online (Sandbox Code Playgroud)

java spring gradle docker dockerfile

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