This is the directory structure of my servlet:
+---build
| \---classes
+---Files
| esoutput.json
| newOutput.xml
| newoutputfinal.xml
| output.xml
|
+---src
| \---com
| \---example
| AddQueryTag.java
| ElasticsearchClient.java
| JsonToXml.java
| mainClass.java
| output.xml
| SaveJsonContent.java
| SaxonImplementation.java
|
+---target
| +---classes
| | +---com
| | | \---example
| | | AddQueryTag.class
| | | ElasticsearchClient.class
| | | JsonToXml.class
| | | mainClass.class
| | | output.xml
| | | SaveJsonContent.class
| | | SaxonImplementation.class
| | |
| | \---META-INF
| | | MANIFEST.MF
| | |
| | \---maven
| | \---com.example
| | \---PIBTest1
| | pom.properties
| | pom.xml
| |
| \---test-classes
\---WebContent
| firstPage.html
|
+---META-INF
| MANIFEST.MF
|
\---WEB-INF
| resultfile.html
| web.xml
|
+---lib
\---src
My main servlet class(mainClass.java) looks like this:
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//Some processing code goes here
//My resultfile.html gets updated and finally I use Request Dispatcher to forward it
request.getServletContext().getRequestDispatcher("/WEB-INF/resultfile.html")
.forward(request, response);
}
This is a search application. User enters the query on “firstpage.html” and gets back the results.
When I first start my web app, “firstpage.html” is started as I configured it in the web.xml file. So when I first start my web app, it shows the “firstpage.html”, then User enters the query and the “resultfile.html” is created. But the web-app shows a blank page instead. I checked the “resultfile.html” and the file is properly generated. So there’s no problem with my code. I want to be able to forward my generated “resultfile.html” page. Am I doing something wrong here? I’m new to Servlets. Thank you everyone.
I’m using Tomcat V7.0 and eclipse.
Update: When the user goes back to the "firstpage.html" and enters the new query, the "resultfile.html" shows the results for the old query. "resultfile.html" doesn't display the updated information.
Update 2: My "resultfile.html" is generated by SaxonImplementation class. The code for that class is as follows:
package com.example;
import java.io.File;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class SaxonImplementation {
public void simpleTransform(String sourcePath, String xsltPath,
String resultDir) {
System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
TransformerFactory tFactory = TransformerFactory.newInstance();
try {
Transformer transformer = tFactory
.newTransformer(new StreamSource(new File(xsltPath)));
transformer.transform(new StreamSource(new File(sourcePath)),
new StreamResult(new File(resultDir)));
} catch (Exception e) {
e.printStackTrace();
}
}
}
I'm calling this class from my doGet method of mainClass.java to do the conversion of XML to HTML file.