Struts2:动态链接重定向?
我是 Struts 的新手, 我使用一个 java 类来生成一个算法,一个我存储在本地的 HTML 文件。 是否可以在我的操作中创建一个链接,以便在操作成功时重定向到临时文件? 这是我的 action.java 类:
String databases;
String sequence;
String algoUsed;
String maxTarget;
String wordSize;
String name;
String sequenceFasta;
boolean lowComplexity;
private String url;
public String getUrl()
{
return url;
}
public String getAlgoUsed() {
return algoUsed;
}
public void setAlgoUsed(String algoUsed) {
this.algoUsed = algoUsed;
}
public String getDatabases() {
return databases;
}
public void setDatabases(String databases) {
this.databases = databases;
}
public String getWordSize() {
return wordSize;
}
public void setWordSize(String wordSize) {
this.wordSize = wordSize;
}
public boolean isLowComplexity() {
return lowComplexity;
}
public void setLowComplexity(boolean lowComplexity) {
this.lowComplexity = lowComplexity;
}
public String getMaxTarget() {
return maxTarget;
}
public void setMaxTarget(String maxTarget) {
this.maxTarget = maxTarget;
}
public String getSequence() {
return sequence;
}
public void setSequence(String sequence) {
this.sequence = sequence;
}
File blast = new File("C:\\dmif-blast\\web\\blast.xml");
File directory = new File("C:\\dmif-blast\\web\\blast\\");
public String commandBlastN() throws Exception{
try {
blast.delete();
File blasthtml = File.createTempFile("blast_", ".html",directory);
ProcessBuilder pb = new ProcessBuilder(
this.blastAllPath,
"-task", "blastn",
"-db", blastDB,
"-query", fasta.getAbsolutePath(),
"-outfmt", "5",
"-word_size", wordSize,
"-num_alignments", maxTarget,
"-num_descriptions", maxTarget,
"-out", blast.getAbsolutePath());
Process proc = pb.start();
System.out.println(pb.command());
if (proc.waitFor() != 0) {
throw new RuntimeException("error occured");
}
} catch (Exception err) {
throw new RuntimeException(err);
}
InputStream in = new FileInputStream(blast);
FileOutputStream out = new FileOutputStream(blasthtml);
out.write(BlastXML2HTML.toHTML(in).getBytes());
out.close();
System.out.println("success......");
url = blasthtml.getCanonicalPath();
return SUCCESS;
}
}
和我的 stuts.xml
<action name="blastn" class="com.ncbi.blast.beanAction.ncbiBlastNAction" method="commandBlastN">
<interceptor-ref name="token"/>
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="execAndWait"/>
<result name="wait">wait.jsp</result>
<result name="error">blastn.jsp</result>
<result name="invalid.token">blastn.jsp</result>
<result name="success" >${url}</result>
</action>
我有一个错误,
"The requested resource (/dmif-blast/C:/dmif-blast/web/blast/blast_7632426713872140252.html) is not available."
感谢您的帮助
编辑: 感谢 Tommi 的解决方案,但它不起作用,现在我有一个新错误:
Stacktraces java.lang.RuntimeException: java.io.IOException: The system cannot find the path specified com.ncbi.blast.beanAction.ncbiBlastNAction.commandBlastN(ncbiBlastNAction.java:168) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280) org.apache.struts2.interceptor.BackgroundProcess$1.run(BackgroundProcess.java:57) java.lang.Thread.run(Thread.java:619)
java.io.IOException: The system cannot find the path specified java.io.WinNTFileSystem.createFileExclusively(Native Method) java.io.File.checkAndCreate(File.java:1704) java.io.File.createTempFile(File.java:1792) com.ncbi.blast.beanAction.ncbiBlastNAction.commandBlastN(ncbiBlastNAction.java:95) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280) org.apache.struts2.interceptor.BackgroundProcess$1.run(BackgroundProcess.java:57) java.lang.Thread.run(Thread.java:619)
I'm a newbie in Struts,
I use a java class that generates a algortihme an HTML file that I store locally.
Is it possible to create a link in my action that redirects to the temporary file in case of success of the action?
This is my action.java class:
String databases;
String sequence;
String algoUsed;
String maxTarget;
String wordSize;
String name;
String sequenceFasta;
boolean lowComplexity;
private String url;
public String getUrl()
{
return url;
}
public String getAlgoUsed() {
return algoUsed;
}
public void setAlgoUsed(String algoUsed) {
this.algoUsed = algoUsed;
}
public String getDatabases() {
return databases;
}
public void setDatabases(String databases) {
this.databases = databases;
}
public String getWordSize() {
return wordSize;
}
public void setWordSize(String wordSize) {
this.wordSize = wordSize;
}
public boolean isLowComplexity() {
return lowComplexity;
}
public void setLowComplexity(boolean lowComplexity) {
this.lowComplexity = lowComplexity;
}
public String getMaxTarget() {
return maxTarget;
}
public void setMaxTarget(String maxTarget) {
this.maxTarget = maxTarget;
}
public String getSequence() {
return sequence;
}
public void setSequence(String sequence) {
this.sequence = sequence;
}
File blast = new File("C:\\dmif-blast\\web\\blast.xml");
File directory = new File("C:\\dmif-blast\\web\\blast\\");
public String commandBlastN() throws Exception{
try {
blast.delete();
File blasthtml = File.createTempFile("blast_", ".html",directory);
ProcessBuilder pb = new ProcessBuilder(
this.blastAllPath,
"-task", "blastn",
"-db", blastDB,
"-query", fasta.getAbsolutePath(),
"-outfmt", "5",
"-word_size", wordSize,
"-num_alignments", maxTarget,
"-num_descriptions", maxTarget,
"-out", blast.getAbsolutePath());
Process proc = pb.start();
System.out.println(pb.command());
if (proc.waitFor() != 0) {
throw new RuntimeException("error occured");
}
} catch (Exception err) {
throw new RuntimeException(err);
}
InputStream in = new FileInputStream(blast);
FileOutputStream out = new FileOutputStream(blasthtml);
out.write(BlastXML2HTML.toHTML(in).getBytes());
out.close();
System.out.println("success......");
url = blasthtml.getCanonicalPath();
return SUCCESS;
}
}
and my stuts.xml
<action name="blastn" class="com.ncbi.blast.beanAction.ncbiBlastNAction" method="commandBlastN">
<interceptor-ref name="token"/>
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="execAndWait"/>
<result name="wait">wait.jsp</result>
<result name="error">blastn.jsp</result>
<result name="invalid.token">blastn.jsp</result>
<result name="success" >${url}</result>
</action>
I have a error
"The requested resource (/dmif-blast/C:/dmif-blast/web/blast/blast_7632426713872140252.html) is not available."
thanks for the help
EDIT :
thanks for the solution Tommi, but it doesn't work, now I have a new error:
Stacktraces java.lang.RuntimeException: java.io.IOException: The system cannot find the path specified com.ncbi.blast.beanAction.ncbiBlastNAction.commandBlastN(ncbiBlastNAction.java:168) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280) org.apache.struts2.interceptor.BackgroundProcess$1.run(BackgroundProcess.java:57) java.lang.Thread.run(Thread.java:619)
java.io.IOException: The system cannot find the path specified java.io.WinNTFileSystem.createFileExclusively(Native Method) java.io.File.checkAndCreate(File.java:1704) java.io.File.createTempFile(File.java:1792) com.ncbi.blast.beanAction.ncbiBlastNAction.commandBlastN(ncbiBlastNAction.java:95) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280) org.apache.struts2.interceptor.BackgroundProcess$1.run(BackgroundProcess.java:57) java.lang.Thread.run(Thread.java:619)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试像这样定义你的结果:
然后在你的行动中,有这样的东西:
Try defining your result like this:
And then in your action, have something like this: