J
jonathan Cook
All,
The first time I make a request to my servlet this calls the doGet
method which builds a page using XML and XSLT depending on the
identity and Authorisation the user has.
A form comes back to client and when submitting this form the doPost
method is called which provides several responses the correct one
being a page which allows the user to make some further selections and
submit which will then call the doPost method again. Consequently
there is a lot of logic in the doPost method.
I understand that I could have more than one servlet but ideally I
would like to have some sort of context associated with each post
request so I can tell whether it is the post from a form or from radio
buttons etc and then chose which code to execute correspondingly.
Would appreciate some help because if the doPost method calls
printCarInformation then it will everytime there is post. I could get
round this by checking input parameters but its all a bit messy.
Thanks
Jonathan Cook
For example this is what the doPost method calls:
private void printCarInformation(HttpServletRequest req,
HttpServletResponse res) throws ServletException, ServiceException,
ParserConfigurationException, SAXException, IOException,
TransformerException
{
// retrieve a PNR
//set HttpServletResponse type
PrintWriter out = res.getWriter();
String pnrLocator = null;
pnrLocator = req.getParameter("pnrlocator");
//System.out.println(pnrLocator.length());
if (pnrLocator.length() == 0 || pnrLocator == null)
{
res.setContentType("text/xml");
String htmlOutput1 = xmlDocManip.getDocAsString();
String XSLTStyleSheet =
"http://localhost:8080/BuildErrorPagePNR.xsl";
String xslDeclaration = "<?xml-stylesheet type=\"text/xsl\"
href=\"" + XSLTStyleSheet + "\"?>";
String xmlVersion = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
String Output = xmlVersion + "\n" + xslDeclaration +"\n" +
htmlOutput1;
out.write(Output);
out.close();
}
else
{
res.setContentType("text/xml");
CarVoucherBusinessLogic bs = new CarVoucherBusinessLogic();
Element PNR = bs.retrievePNR(pnrLocator);
Document doc = bs.buildCarSegments(PNR);
String XSLTStyleSheet = "http://localhost:8080/style2.xsl";
Element rootElement = doc.getDocumentElement();
String element = XMLUtils.ElementToString(rootElement);
String xslDeclaration = "<?xml-stylesheet type=\"text/xsl\"
href=\"" + XSLTStyleSheet + "\"?>";
String xmlVersion = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
String htmlOutput = xmlVersion + "\n" + xslDeclaration +"\n" +
element;
//output html to page
//htmlOutput = xmlDocManip.applyTransformationUsingBrowser();
out.write(htmlOutput);
}
}
The first time I make a request to my servlet this calls the doGet
method which builds a page using XML and XSLT depending on the
identity and Authorisation the user has.
A form comes back to client and when submitting this form the doPost
method is called which provides several responses the correct one
being a page which allows the user to make some further selections and
submit which will then call the doPost method again. Consequently
there is a lot of logic in the doPost method.
I understand that I could have more than one servlet but ideally I
would like to have some sort of context associated with each post
request so I can tell whether it is the post from a form or from radio
buttons etc and then chose which code to execute correspondingly.
Would appreciate some help because if the doPost method calls
printCarInformation then it will everytime there is post. I could get
round this by checking input parameters but its all a bit messy.
Thanks
Jonathan Cook
For example this is what the doPost method calls:
private void printCarInformation(HttpServletRequest req,
HttpServletResponse res) throws ServletException, ServiceException,
ParserConfigurationException, SAXException, IOException,
TransformerException
{
// retrieve a PNR
//set HttpServletResponse type
PrintWriter out = res.getWriter();
String pnrLocator = null;
pnrLocator = req.getParameter("pnrlocator");
//System.out.println(pnrLocator.length());
if (pnrLocator.length() == 0 || pnrLocator == null)
{
res.setContentType("text/xml");
String htmlOutput1 = xmlDocManip.getDocAsString();
String XSLTStyleSheet =
"http://localhost:8080/BuildErrorPagePNR.xsl";
String xslDeclaration = "<?xml-stylesheet type=\"text/xsl\"
href=\"" + XSLTStyleSheet + "\"?>";
String xmlVersion = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
String Output = xmlVersion + "\n" + xslDeclaration +"\n" +
htmlOutput1;
out.write(Output);
out.close();
}
else
{
res.setContentType("text/xml");
CarVoucherBusinessLogic bs = new CarVoucherBusinessLogic();
Element PNR = bs.retrievePNR(pnrLocator);
Document doc = bs.buildCarSegments(PNR);
String XSLTStyleSheet = "http://localhost:8080/style2.xsl";
Element rootElement = doc.getDocumentElement();
String element = XMLUtils.ElementToString(rootElement);
String xslDeclaration = "<?xml-stylesheet type=\"text/xsl\"
href=\"" + XSLTStyleSheet + "\"?>";
String xmlVersion = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
String htmlOutput = xmlVersion + "\n" + xslDeclaration +"\n" +
element;
//output html to page
//htmlOutput = xmlDocManip.applyTransformationUsingBrowser();
out.write(htmlOutput);
}
}