我正在使用早期版本的java 8工作代码,我用它从列表中获取唯一值但是因为我升级到JDK 66它给了我一个错误
类型不匹配:无法转换List<Object>为List<String>
List<String> instList = new ArrayList<String>();
while (res.next()) {
instList.add(res.getString("INST").toString());
}
List<String> instListF = instList.stream().distinct().collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
当水库的结果集我是从数据库中获取,不知道什么是错的任何想法?
我正在尝试使用angular http post将数据发送到servlet,
var httpPostData = function (postparameters,postData){
var headers = {
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS',
'Accept': 'application/json'
};
return $http ({
method : 'POST',
url : 'http://localhost:8080/json/jasoncontroller',
params : postparameters,
headers: headers,
data : postData
}).success (function (responseData){
return responseData.data;
})
}
Run Code Online (Sandbox Code Playgroud)
但我继续得到错误,请求资源上没有'Access-Control-Allow-Origin'标头.因此不允许原点'null'访问.
我确实在我的servlet上设置了以下标题
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
response.addHeader("Access-Control-Max-Age", "3600");
response.addHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
Run Code Online (Sandbox Code Playgroud)
如果我从http帖子中删除数据它工作正常,但数据没有运气.
我一直在学习JAVA,我对代码有一点疑问:
class apple {
public static void main(String[] args) {
int[] num = new int[3];
Scanner input = new Scanner(System.in);
for (int i = 0; i < num.length; i++) {
try {
num[i] = input.nextInt();
} catch (Exception e) {
System.out
.println("Invalid number..assigning default value 20");
num[i] = 20;
}
}
for (int i = 0; i < num.length; i++) {
System.out.println(num[i]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我编写了一个小程序来处理异常,如果用户输入不是Int抛出异常并分配默认值.如果我把扫描器语句放在for循环中,它工作正常,但如果我把它带到它之外,它会分配抛出异常的相同值,即我输入的是char而不是int.但是如果我输入所有整数,它会在数组中分配正确的值.
Scanner input = new Scanner(System.in);
Run Code Online (Sandbox Code Playgroud)
我希望你们理解我的问题.
我必须使用ng-repeat在html页面中显示表格。表中的大多数条目都具有null数据,但是我无法将null替换为空白或字符串null。我尝试了{{行|| 'null'}},但没有帮助。当行产生大量的空值时,它会完全弄乱表。
<table>
<tr>
<th ng-repeat="colname in sqldata.collist">{{colname}}</th>
</tr>
<tr ng-repeat="rows in sqldata.tablist">
<td ng-repeat="row in rows">{{ row || 'null' }}</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
请看下面的代码.
import { Component,ViewChild,QueryList,ViewChildren } from '@angular/core'
@Component ({
selector : 'other-component',
template : `
<h2>OtherComponent<h2>
<table #tab id="tab">
<tr *ngFor="let val of valArray">
<td>{{val}}</td>
<input type="checkbox" [value]="val">
</tr>
</table>
<button (click)="getChecked()">click me</button>`
})
export class OtherComponent{
valArray = ['one','two','three','four'];
@ViewChild ('tab') elem;
getChecked = () => {
console.log (this.elem.nativeElement.children[0].children)
}
}
Run Code Online (Sandbox Code Playgroud)
在表格行的末尾有一个已分配行值(JSON对象)的复选框,现在我想收集角度2中的所有复选框.
在简单的JavaScript中,我可以像下面这样轻松地完成此操作
var yy = document.getElementById('tab').getElementsByTagName('input');
Run Code Online (Sandbox Code Playgroud)
我得到了我想要的东西 this.elem.nativeElement.children[0].children
这给了我一系列tr元素,我从中检查输入框
在角度2中有更好的方法吗?
我想知道启动/停止postgres数据库的正确方法。有两种方法
pg_ctl start/stopservice postgresql start/stop我想知道它们之间的区别,我应该使用哪一个?是他们的优点/缺点。
我在网上检查,但没有得到满意的答复。
提前致谢
我正在尝试使用 java 程序使用 jsch 运行 shell 命令。命令需要 sudo 访问权限才能执行。以下是我的代码示例。
String command1="sudo restart oraserv";
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
Session session;
try {
session = jsch.getSession(user, host, 22);
session.setPassword(password);
session.setConfig(config);
session.connect();
System.out.println("Connected");
Channel channel=session.openChannel("exec");
((ChannelExec) channel).setCommand(command1);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
InputStream in=channel.getInputStream();
((ChannelExec)channel).setPty(true);
channel.connect();
byte[] tmp=new byte[1024];
while(true){
while(in.available()>0){
int i=in.read(tmp, 0, 1024);
if(i<0)break;
System.out.print(new String(tmp, 0, i));
}
if(channel.isClosed()){
System.out.println("exit-status: "+channel.getExitStatus());
break;
}
try{Thread.sleep(1000);}catch(Exception ee){}
}
channel.disconnect();
session.disconnect();
System.out.println("DONE");
} catch (JSchException | IOException e) …Run Code Online (Sandbox Code Playgroud) 我有简单的角度2形式代码如下
<form [formGroup]="myForm" (ngSubmit)="onSubmit()" class="formcss">
Username<br>
<input type="text" formControlName="username"><br><br>
<div>
Email<br>
<input id="email" type="text" formControlName="email">
<div *ngIf="myForm.find('email').valid">Invalid Email</div><br><br>
Password<br>
</div>
<input type="text" formControlName="password"><br><br>
<h3>Hobbies</h3>
<input type="text"><br><br>
<button>Add Hobby</button>
<button type="submit" [ngStyle]="{ background:'green'}" [disabled]="!myForm.valid">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)
我试图显示消息"无效的电子邮件"是电子邮件提交不通过验证器,但得到此错误
error_handler.js:45 EXCEPTION: self.context.myForm.find is not a function
Run Code Online (Sandbox Code Playgroud)
我正在使用角度2的最终版本.任何想法?
我的网页上有很多图片.
<img id="a" src="1.jpg">
<br>
<img id="b" src="2.jpg">
Run Code Online (Sandbox Code Playgroud)
我试图通过使用下面的javascript获得点击图像的"src".
var getImageName = function(){
document.onclick = function(){
var image = this.getAttribute("src");
alert(image);
}}
getImageName();
Run Code Online (Sandbox Code Playgroud)
但是它给出了一个错误this.getAttribute不是函数.
任何的想法?提前致谢
java ×4
javascript ×3
angular ×2
angularjs ×2
typescript ×2
collectors ×1
java-8 ×1
jquery ×1
postgresql ×1
servlets ×1
shell ×1
su ×1
sudo ×1
unix ×1