Note that there are some explanatory texts on larger screens.

plurals
  1. POStruts2 : dynamic link redirects?
    primarykey
    data
    text
    <p>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:</p> <pre><code>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; } </code></pre> <p>}</p> <p>and my stuts.xml</p> <pre><code> &lt;action name="blastn" class="com.ncbi.blast.beanAction.ncbiBlastNAction" method="commandBlastN"&gt; &lt;interceptor-ref name="token"/&gt; &lt;interceptor-ref name="defaultStack"/&gt; &lt;interceptor-ref name="execAndWait"/&gt; &lt;result name="wait"&gt;wait.jsp&lt;/result&gt; &lt;result name="error"&gt;blastn.jsp&lt;/result&gt; &lt;result name="invalid.token"&gt;blastn.jsp&lt;/result&gt; &lt;result name="success" &gt;${url}&lt;/result&gt; &lt;/action&gt; </code></pre> <p>I have a error </p> <pre><code>"The requested resource (/dmif-blast/C:/dmif-blast/web/blast/blast_7632426713872140252.html) is not available." </code></pre> <p>thanks for the help</p> <p>EDIT : thanks for the solution Tommi, but it doesn't work, now I have a new error:</p> <pre><code>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) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload