我是基础知识编程的新手,我已经习惯了Java.
我想编写一个代码来计算第n次幂的数字而不使用循环.我一直在尝试使用大约4天前我所了解的"commons lang"中的重复方法.我在这个网站和其他网站上找到了很多信息,帮助我了解如何使用这个包装.
到目前为止,我下载了commons-lang3-3.1,然后将文件夹保存在与我的项目相同的文件夹中,并将jar文件添加到我的项目库中:
右键单击库
1然后添加JAR /文件夹
2然后我打开了commons-lang3-3.1文件夹
3并从多个4个选项中选择了"commons-lang3-3.1.jar":
这是一个代码,用于测试我从其他问题之一: -
0. package refreshingmemory;
1. import org.apache.commons.lang.StringUtils;
2. public class RefreshingMemory {
3.
4. public static void main(String[] args) {
5. String str = "abc";
6. String repeated = StringUtils.repeat(str, 3);
7. repeated.equals("abcabcabc");
8.
9. }
10. }
Run Code Online (Sandbox Code Playgroud)
第1行说包org.apache.commons.lang不存在.
第7行说应检查方法返回值
,如果我删除第1行,我在第6行找不到符号
如何成功导入?
Netbeans的屏幕截图:
我正在使用Java中的JSON将XML转换为JSON.我有这个实现反转所有子元素的问题.
当我传递这个XML时:
<Person><Child1>a</Child1><Child2>b</Child2></Person>
Run Code Online (Sandbox Code Playgroud)
我最终会得到一个让孩子倒置的JSON:
{"Person":{"Child2":"b", "Child1":"a"}}
Run Code Online (Sandbox Code Playgroud)
我的Java代码:
JSONObject jsonObject= XML.toJSONObject("<Person><Child1>a</Child1><Child2>b</Child2></Person>");
String myJSONString = jsonObject.toString(4);
Run Code Online (Sandbox Code Playgroud)
如何在保持元素顺序的情况下转换为JSON(如XML)?
我该如何返回这样的枚举?
在我用int返回之前,如果没有,则返回0,如果是,则返回1,如果是其他则返回2.但这不是一个好方法.那应该怎么做呢.我的代码:
class SomeClass{
public enum decizion{
YES, NO, OTHER
}
public static enum yourDecizion(){
//scanner etc
if(x.equals('Y')){
return YES;
}
else if (x.equals('N')){
return NO;
}
else{
return OTHER;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用JCo库从Java调用SAP中的函数.到目前为止我的调用工作正常,但是当我在互联网上寻求帮助时,总会有一个JCoClient
用于获取功能,进行提交等等.
但是JCO 3中不存在JCoClient类.
相反,我使用JCoDestination
我用配置文件创建的实例.
JCoClient和JCoDestination有什么区别?为什么没有人谈论JCoDestination,但总是JCoClient?
我有一个SFTP(Windows与WinSSHD)的问题.我尝试用Apache Commons VFS在一个文件夹中写一个文件.在本地SFTP上我没有上传的问题但在第二个SFTP上我总是得到以下错误.
FTP看起来像这样:
我需要上传到文件夹"alis".奇怪的是它没有User/Group和770权限.但是,使用FileZilla文件上传工作正常(使用相同的登录).
在文件夹"alis"上执行"manager.resolveFile()"(我尝试上传到此文件夹)并打印".getType()"我获取信息"文件"而不是预期的"文件夹".
有没有人知道为什么VFS会将文件夹识别为文件或为什么上传不起作用?
将文件上载到SFTP时的例外情况:
Exception in thread "main" java.lang.RuntimeException: org.apache.commons.vfs2.FileSystemException: Could not copy "file:///D:/Test/test.txt" to "sftp://user:***@host/.../alis/test.txt".
at test.Test.upload(Test.java:77)
at test.Test.main(Test.java:22)
Caused by: org.apache.commons.vfs2.FileSystemException: Could not copy "file:///D:/Test/test.txt" to "sftp://user:***@host/.../alis/test.txt".
at org.apache.commons.vfs2.provider.AbstractFileObject.copyFrom(AbstractFileObject.java:1062)
at test.Test.upload(Test.java:73)
... 1 more
Caused by: org.apache.commons.vfs2.FileSystemException: Could not create folder "sftp://user:***@host/.../alis" because it already exists and is a file.
at org.apache.commons.vfs2.provider.AbstractFileObject.createFolder(AbstractFileObject.java:968)
at org.apache.commons.vfs2.provider.AbstractFileObject.getOutputStream(AbstractFileObject.java:1424)
at org.apache.commons.vfs2.provider.DefaultFileContent.getOutputStream(DefaultFileContent.java:461)
at org.apache.commons.vfs2.provider.DefaultFileContent.getOutputStream(DefaultFileContent.java:441)
at org.apache.commons.vfs2.FileUtil.copyContent(FileUtil.java:111)
at org.apache.commons.vfs2.provider.AbstractFileObject.copyFrom(AbstractFileObject.java:1053)
... 2 more
Run Code Online (Sandbox Code Playgroud)
源代码:(运行示例,您需要"jsch-0.1.50.jar")
import java.io.File;
import org.apache.commons.vfs2.FileObject; …
Run Code Online (Sandbox Code Playgroud) 在WSO2 ESB中,我在repository/log目录中有几个日志文件.有什么区别,如果一切正常,我应该用哪一个来进行日常控制?
这里是日志文件列表:
我正在使用JCo库访问SAP标准BAPI。嗯,除了我使用TID(TransactionID)时RETURN表始终为空之外,其他所有内容也都可以正常工作。
当我仅删除TID时,我得到的RETURN表中填充有Warnings等。但是不幸的是,我需要对事务性BAPI使用TID,否则不会提交更改。
为什么使用TID时RETURN TABLE为空?
还是我必须将更改提交到事务性BAPI?
这是BAPI访问的伪代码:
import com.sap.conn.jco.*;
import org.apache.commons.logging.*;
public class BapiSample {
private static final Log logger = LogFactory.getLog(BapiSample.class);
private static final String CLIENT = "400";
private static final String INSTITUTION = "1000";
protected JCoDestination destination;
public BapiSample() {
this.destination = getDestination("mySAPConfig.properties");
}
public void execute() {
String tid = null;
try {
tid = destination.createTID();
JCoFunction function = destination.getRepository().getFunction("BAPI_PATCASE_CHANGEOUTPATVISIT");
function.getImportParameterList().setValue("CLIENT", CLIENT);
function.getImportParameterList().setValue("INSTITUTION", INSTITUTION);
function.getImportParameterList().setValue("MOVEMNT_SEQNO", "0001");
// Here we will then all parameters of the BAPI....
// ... …
Run Code Online (Sandbox Code Playgroud) 我不知道如何继续,但我总是得到新的JSF 1.2 Web应用程序的"java.lang.RuntimeException:找不到FacesContext".我确定这只是我找不到的一些配置.
第一个f:
或h:
标记出现异常.已经与重要<f:view>
的开始.
我的 index.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<f:view>
<html>
<head>
<title>MyWebsite</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<div>MyContent</div>
</body>
</html>
</f:view>
Run Code Online (Sandbox Code Playgroud)
我web.xml
看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jsp</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping> …
Run Code Online (Sandbox Code Playgroud) 在WSO2 ESB代理服务中,我如何根据某些webservice响应中的整数值进行迭代,就像"foreach"一样:
例如这样的响应消息:
<Response>
<noOfcustomers>10</noOfCustomers>
</Response>
Run Code Online (Sandbox Code Playgroud)
我需要迭代10次(根据客户数量)
这可能吗?我怎样才能实现这一目标?
谢谢你的帮助!
我正在访问MongoDB,并希望在Java中重用典型的命令行查询.我知道可以使用BasicDBObject,但我想使用这样的命令行查询:
db.MyCollection.find()
Run Code Online (Sandbox Code Playgroud)
我现在尝试使用数据库的command()方法:
MongoClient mongoClient = new MongoClient("localhost", 27017);
DB db = mongoClient.getDB("MyDatabase");
CommandResult result= db.command("db.MyCollection.find()");
JSONObject resultJson = new JSONObject(result.toString());
System.out.println(resultJson.toString(4));
Run Code Online (Sandbox Code Playgroud)
但这会给我带来以下结果.
"ok": 0,
"code": 59,
"errmsg": "no such cmd: db.MyCollection.find()",
"bad cmd": {"db.MyCollection.find()": true},
"serverUsed": "localhost:27017"
Run Code Online (Sandbox Code Playgroud)
如何在Java中运行命令行查询?
我不想使用DBCollection类 - 因为它不再可能为不同的集合运行查询.
DBCollection collection = db.getCollection("MyCollection");
collection.find(); //NOT THIS
Run Code Online (Sandbox Code Playgroud) 我有几个代理(使用 JMS 传递消息),我猜有一个代理总是在我的wso2carbon.log
文件中生成警告:
WARN {org.apache.axis2.transport.jms.JMSSender} - Did not receive a JMS response within 30000 ms to destination : temp-queue://ID:EAI-P01-59160-1365080800632-57287:1:1 with JMS correlation ID : ID:EAI-P01-59160-1365080800632-57285:1:1:1:1 {org.apache.axis2.transport.jms.JMSSender}
WARN {org.apache.synapse.core.axis2.TimeoutHandler} - Expiring message ID : urn:uuid:5428da0b-8f52-49ea-bcff-66df02a54daf; dropping message after global timeout of : 120 seconds {org.apache.synapse.core.axis2.TimeoutHandler}
Run Code Online (Sandbox Code Playgroud)
为什么我会收到这些警告,我总是指定属性<property name="OUT_ONLY" value="true"/>
.
不幸的是,我无法真正重现它,但也许有人知道为什么会发生这种情况(发送到 JMS?)
当我在WSO2 API管理器中发布API时,会发生以下错误:
Gateway Failures
Failed to Publish Environments
Production and Sandbox
Error while obtaining API information from gateway. Error while obtaining API information from gateway. Authentication failure
Run Code Online (Sandbox Code Playgroud)