嗨,我有类似以下的东西,使URL连接并检索数据.问题是,当我点击需要身份验证的页面时,我会获得登录页面.我不确定如何在URLConnection中传递用户名和密码.我正在使用JAAS认证的网站.
import java.net.URL;
import java.net.URLConnection;
.....
URL location = new URL("www.sampleURL.com");
URLConnection yc = location.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
data += inputLine + "\n";
in.close();
Run Code Online (Sandbox Code Playgroud)
我试过这样的东西,但似乎没有用......
URL url = new URL("www.myURL.com");
URLConnection connection = url.openConnection();
String login = "username:password";
String encodedLogin = new BASE64Encoder().encodeBuffer(login.getBytes());
connection.setRequestProperty("Proxy-Authorization", "Basic " + encodedLogin);
Run Code Online (Sandbox Code Playgroud) 我正在使用哈希表实现perl fib:
#!/usr/bin/perl
use strict;
use warnings;
no warnings 'recursion';
my %m_fib = (0,1,1,1);
while (my $a = <STDIN>) {
print "--".&fib($a)."\n";
}
sub fib {
foreach my $i (@_) {
if (not defined $m_fib{$i}) {
$m_fib{$i} = &fib($i - 1) + &fib($i - 2);
}
return $m_fib{$i};
}
}
Run Code Online (Sandbox Code Playgroud)
输入大于1时效果很好,但默认为0或1.
哈希应该没问题,因为它返回了正确的结果,但是如果我用0或1提供它,为什么它不起作用?
我有一个error-page
指令将所有异常重定向到错误显示页面
我的web.xml
:
<web-app [...]>
[...]
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/view/error.xhtml</location>
</error-page>
</web-app>
Run Code Online (Sandbox Code Playgroud)
它适用于几乎所有异常,但今天我注意到有时会记录JSF错误并且不处理异常(即,没有重定向到错误页面).
这是我在日志中的内容:
javax.enterprise.resource.webcontainer.jsf.context || JSF1073: javax.faces.event.AbortProcessingException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=searchForm:j_idt147, Message=/view/listView.xhtml @217,7 actionListener="#{listController.nextPageClicked}": java.lang.NullPointerException
javax.enterprise.resource.webcontainer.jsf.context || /view/listView.xhtml @217,7 actionListener="#{listController.nextPageClicked}": java.lang.NullPointerException
javax.faces.event.AbortProcessingException: /view/listView.xhtml @217,7 actionListener="#{listController.nextPageClicked}": java.lang.NullPointerException
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:182)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.doChainInvoke(StandardPipeline.java:600)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:96)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162) …
Run Code Online (Sandbox Code Playgroud) 好的,所以我注意到perl中grep的一些反直觉行为,具体取决于我打开文件的方式.如果我打开一个只读的文件,(<)就可以了.如果我打开它读写,(+ <),它可以工作,但如果我打开它追加读取,它不会.(+ >>)
我确信这可以解决,但我很好奇它为什么这样工作.有人有一个很好的解释?
鉴于以下test.txt
文件:
a
b
c
Run Code Online (Sandbox Code Playgroud)
和一份greptest.pl
文件:
#!/usr/bin/perl
use strict;
use warnings;
open(RFILE, '<', "test.txt")
or die "Read failed: $!";
if(grep /b/, <RFILE>) {print "Found when opened read\n";}
else {print "Not found when opened read\n";}
close RFILE;
open(RWFILE, '+<', "test.txt")
or die "Write-read failed: $!";
if(grep /b/, <RWFILE>) {print "Found when opened write-read\n";}
else {print "Not found when opened write-read\n";}
close RWFILE;
open(AFILE, '+>>', "test.txt")
or die "Append-read failed: $!";
if(grep /b/, <AFILE>) {print …
Run Code Online (Sandbox Code Playgroud) 我是 Java 新手。
我正在尝试连接到数据库,但无法编译我的测试程序 ( helloworld.java
)
[root@localhost my_src]# gcc -v
Using built-in specs.
Target: i386-redhat-linux
........... --enable-languages=c,c++,objc,obj-c++,java,fortran,ada..............
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)
[root@localhost my_src]# gcc -x java helloworld.java
gcc: error trying to exec 'jc1': execvp No such a file or directory
Run Code Online (Sandbox Code Playgroud)
我知道我必须安装 JDK 才能编写 Java 类,但 gcc 不足以编译我的 helloworld.java?如果是这样的话,上面有什么问题吗?我缺少什么吗?
我需要读取/复制文件(test.pl)的内容,就像格式化和发送电子邮件一样.
我使用以下代码,但我无法打印任何东西.
即使该文件存在于同一目录中,我也会收到此错误.
Failed: No such file or directory
Run Code Online (Sandbox Code Playgroud)
码:
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
open my $fh, '<', 'test.pl '
or die "Failed: $!\n";
my $text = do {
local $/;
<$fh>
};
close $fh
or die "Failed again: $!\n";
print $text, "\n";
Run Code Online (Sandbox Code Playgroud) 我正在使用PrimeFaces,我想<p:graphicImage>
在执行上传操作后显示上传图像的预览.
我正在学习C.我需要定义一个函数来键入void *
转换为所需类型的值.我不确定我是否完全理解我需要做什么.这是我的尝试.有人可以看看,让我知道它是否正确?如果没有,我该如何解决?提前谢谢您的时间.
void print_type(TYPE a)
{
void *v_ptr;
v_ptr = &a;
}
Run Code Online (Sandbox Code Playgroud) perl ×3
java ×2
ajax ×1
architecture ×1
c ×1
casting ×1
graphicimage ×1
java-ee ×1
jsf ×1
jsf-2 ×1
pointers ×1
primefaces ×1
proxy ×1
types ×1