Hi
I have this servlet which runs on myPc at the moment and is executed via
anyway this servlet creats and XML Document.
Then i want to call another class which code iwill show below. this class reads the XML values and stores them in an array. the other class graps this infprmation and for now loops through it and displays it.
the problem is i can't seem to get the XML reader to find the file on the system.
well heres the code hope someone can help
OH AND ALSO THE DIRECTORY STRUCTURE ON MY SYSTEM IS
..\jsdk2.1 IS THE ROOT AND WHERE THE xml APPEARS
..\jsdk2.1\examples\WEB-INF\servlets THIS IS WHERE THE SERVLET AND OTHER CODE APPEARS
SERVLET
/*
*
*This servlet creates the web form through which you can insert a new record
*into the database.
*
*It will check to ensure that data is entered into all
*
*/
import java.io.*;
//import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.XMLWriter;
public class Fiddle extends HttpServlet {
public ResourceBundle rb = ResourceBundle.getBundle("LocalStrings"
public String tagStart;
public String tableName = "none";
public String[] details;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("text/html"
PrintWriter out = response.getWriter();
out.println("<html>"
out.println("<body>"
out.println("<head>"
out.println("<title>Insert Details in DB2</title>"
out.println("</head>"
out.println("<body>"
out.println("<h1>Database Input</h1>"
out.println("<table border=0><tr><td>"
out.println("<P>"
out.print("<form action=\""
out.print("Fiddle\" "
out.println("method=POST>"
out.println(rb.getString("requestparams.DB_NAME");
out.println("<input type=text size=20 name=DB_NAME>"
out.println("<br>"
out.println(rb.getString("requestparams.NB_CLIENT");
out.println("<input type=text size=20 name=NB_CLIENT>"
out.println("<br>"
out.println(rb.getString("requestparams.TY_CLIENT");
out.println("<input type=text size=20 name=TY_CLIENT>"
out.println("<br>"
out.println(rb.getString("requestparams.TX_SRCE_ENTRY_CHNG");
out.println("<input type=text size=20 name=TX_SRCE_ENTRY_CHNG>"
out.println("<br>"
out.println(rb.getString("requestparams.NM_OPER_MAKNG_CHNG");
out.println("<input type=text size=20 name=NM_OPER_MAKNG_CHNG>"
out.println("<br>"
out.println(rb.getString("requestparams.DT_UPDATE");
out.println("<input type=text size=20 name=DT_UPDATE>"
out.println("<br>"
out.println(rb.getString("requestparams.TM_UPDATE");
out.println("<input type=text size=20 name=TM_UPDATE>"
out.println("<br>"
out.println(rb.getString("requestparams.CD_RSN_REMO_CLIENT");
out.println("<input type=text size=20 name=CD_RSN_REMO_CLIENT>"
out.println("<br>"
out.println(rb.getString("requestparams.DT_REMOVAL_CLIENT");
out.println("<input type=text size=20 name=DT_REMOVAL_CLIENT>"
out.println("<br>"
out.println(rb.getString("requestparams.MB_REPLACE_CLIENT");
out.println("<input type=text size=20 name=MB_REPLACE_CLIENT>"
out.println("<br>"
out.println(rb.getString("requestparams.NB_PHONETIC_NM");
out.println("<input type=text size=20 name=NB_PHONETIC_NM>"
out.println("<br>"
out.println(rb.getString("requestparams.NB_DRVR_LCNCE");
out.println("<input type=text size=20 name=NB_DRVR_LCNCE>"
out.println("<br>"
out.println(rb.getString("requestparams.IN_VIC_LICENCE");
out.println("<input type=text size=20 name=IN_VIC_LICENCE>"
out.println("<br>"
out.println("<input type=submit>"
out.println("</form>"
out.println("</td><td>"
String DB_NAME = request.getParameter("DB_NAME"
String NB_CLIENT = request.getParameter("NB_CLIENT"
String TY_CLIENT = request.getParameter("TY_CLIENT"
String TX_SRCE_ENTRY_CHNG = request.getParameter("TX_SRCE_ENTRY_CHNG"
String NM_OPER_MAKNG_CHNG = request.getParameter("NM_OPER_MAKNG_CHNG"
String DT_UPDATE = request.getParameter("DT_UPDATE"
String TM_UPDATE = request.getParameter("TM_UPDATE"
String CD_RSN_REMO_CLIENT = request.getParameter("CD_RSN_REMO_CLIENT"
String DT_REMOVAL_CLIENT = request.getParameter("DT_REMOVAL_CLIENT"
String MB_REPLACE_CLIENT = request.getParameter("MB_REPLACE_CLIENT"
String NB_PHONETIC_NM = request.getParameter("NB_PHONETIC_NM"
String NB_DRVR_LCNCE = request.getParameter("NB_DRVR_LCNCE"
String IN_VIC_LICENCE = request.getParameter("IN_VIC_LICENCE"
out.println(rb.getString("requestparams.params-in-req" + "<br>"
out.println("<p>1</p><br>"
if (DB_NAME == null || NB_CLIENT == null || TY_CLIENT == null ||
TX_SRCE_ENTRY_CHNG == null || NM_OPER_MAKNG_CHNG == null ||
DT_UPDATE == null || TM_UPDATE == null ||CD_RSN_REMO_CLIENT == null ||
DT_REMOVAL_CLIENT == null || MB_REPLACE_CLIENT == null ||NB_PHONETIC_NM == null ||
NB_DRVR_LCNCE == null || IN_VIC_LICENCE == null)
{
out.println("<p>2</p><br>"
out.println(rb.getString("requestparams.no-params");
}
else if (DB_NAME.equals("" || NB_CLIENT.equals("" || TY_CLIENT.equals("" ||
TX_SRCE_ENTRY_CHNG.equals("" || NM_OPER_MAKNG_CHNG.equals("" ||
DT_UPDATE.equals("" || TM_UPDATE.equals("" ||CD_RSN_REMO_CLIENT.equals("" ||
DT_REMOVAL_CLIENT.equals("" || MB_REPLACE_CLIENT.equals("" ||NB_PHONETIC_NM.equals("" ||
NB_DRVR_LCNCE.equals("" || IN_VIC_LICENCE.equals("")
{
out.println("<p>2</p><br>"
out.println(rb.getString("requestparams.no-params");
}
else {
out.println("<p>3</p><br>"
out.println(rb.getString("requestparams.DB_NAME");
out.println(" = " + DB_NAME + "<br>"
out.println(rb.getString("requestparams.NB_CLIENT");
out.println(" = " + NB_CLIENT + "<br>"
out.println(rb.getString("requestparams.TY_CLIENT");
out.println(" = " + TY_CLIENT + "<br>"
out.println(rb.getString("requestparams.TX_SRCE_ENTRY_CHNG");
out.println(" = " + TX_SRCE_ENTRY_CHNG + "<br>"
out.println(rb.getString("requestparams.NM_OPER_MAKNG_CHNG");
out.println(" = " + NM_OPER_MAKNG_CHNG + "<br>"
out.println(rb.getString("requestparams.DT_UPDATE");
out.println(" = " + DT_UPDATE + "<br>"
out.println(rb.getString("requestparams.TM_UPDATE");
out.println(" = " + TM_UPDATE + "<br>"
out.println(rb.getString("requestparams.CD_RSN_REMO_CLIENT");
out.println(" = " + CD_RSN_REMO_CLIENT + "<br>"
out.println(rb.getString("requestparams.DT_REMOVAL_CLIENT");
out.println(" = " + DT_REMOVAL_CLIENT + "<br>"
out.println(rb.getString("requestparams.MB_REPLACE_CLIENT");
out.println(" = " + MB_REPLACE_CLIENT + "<br>"
out.println(rb.getString("requestparams.NB_PHONETIC_NM");
out.println(" = " + NB_PHONETIC_NM + "<br>"
out.println(rb.getString("requestparams.NB_DRVR_LCNCE");
out.println(" = " + NB_DRVR_LCNCE + "<br>"
out.println(rb.getString("requestparams.IN_VIC_LICENCE");
out.println(" = " + IN_VIC_LICENCE + "<br>"
}
out.println("</td></tr></table>"
out.println("</body>"
out.println("</html>"
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
write(createDocument(request));
RetreiveData ret = new RetreiveData();
ret.getData("output.xml/../../.."
String[] tem = ret.details;
String val;
PrintWriter out = response.getWriter();
if(tem != null){
for(int i = 0; i<tem.length;i++){
out.println("<p>"+tem+"</p><br>"
}
}
else{
out.println("no values entered"
}
doGet(request, response);
}
public Document createDocument(HttpServletRequest request) {
Document document = DocumentHelper.createDocument();
String DB_NAME = request.getParameter("DB_NAME"
String NB_CLIENT = request.getParameter("NB_CLIENT"
String TY_CLIENT = request.getParameter("TY_CLIENT"
String TX_SRCE_ENTRY_CHNG = request.getParameter("TX_SRCE_ENTRY_CHNG"
String NM_OPER_MAKNG_CHNG = request.getParameter("NM_OPER_MAKNG_CHNG"
String DT_UPDATE = request.getParameter("DT_UPDATE"
String TM_UPDATE = request.getParameter("TM_UPDATE"
String CD_RSN_REMO_CLIENT = request.getParameter("CD_RSN_REMO_CLIENT"
String DT_REMOVAL_CLIENT = request.getParameter("DT_REMOVAL_CLIENT"
String MB_REPLACE_CLIENT = request.getParameter("MB_REPLACE_CLIENT"
String NB_PHONETIC_NM = request.getParameter("NB_PHONETIC_NM"
String NB_DRVR_LCNCE = request.getParameter("NB_DRVR_LCNCE"
String IN_VIC_LICENCE = request.getParameter("IN_VIC_LICENCE"
if (DB_NAME.equals("" || NB_CLIENT.equals("" || TY_CLIENT.equals("" ||
TX_SRCE_ENTRY_CHNG.equals("" || NM_OPER_MAKNG_CHNG.equals("" ||
DT_UPDATE.equals("" || TM_UPDATE.equals("" ||CD_RSN_REMO_CLIENT.equals("" ||
DT_REMOVAL_CLIENT.equals("" || MB_REPLACE_CLIENT.equals("" ||NB_PHONETIC_NM.equals("" ||
NB_DRVR_LCNCE.equals("" || IN_VIC_LICENCE.equals("") {
Element root = document.addElement( "root" );
Element author1 = root.addElement( "author" )
.addAttribute( "name", "James" )
.addAttribute( "location", "UK" )
.addText( "James Strachan" );
Element author2 = root.addElement( "author" )
.addAttribute( "name", "Bob" )
.addAttribute( "location", "US" )
.addText( "Bob McWhirter" );
return document;
}
else {
Element root = document.addElement( "DB_NAME"
Element detail1 = root.addElement( "NB_CLIENT" )
.addText( "" + NB_CLIENT );
Element detail2 = root.addElement( "TY_CLIENT" )
.addText( "" + TY_CLIENT );
Element detail3 = root.addElement( "TX_SRCE_ENTRY_CHNG" )
.addText( "" + TX_SRCE_ENTRY_CHNG );
Element detail4 = root.addElement( "NM_OPER_MAKNG_CHNG" )
.addText( "" + NM_OPER_MAKNG_CHNG );
Element detail5 = root.addElement( "DT_UPDATE" )
.addText( "" + DT_UPDATE );
Element detail6 = root.addElement( "TM_UPDATE" )
.addText( "" + TM_UPDATE );
Element detail7 = root.addElement( "CD_RSN_REMO_CLIENT" )
.addText( "" + CD_RSN_REMO_CLIENT );
Element detail8 = root.addElement( "DT_REMOVAL_CLIENT" )
.addText( "" + DT_REMOVAL_CLIENT );
Element detail9 = root.addElement( "MB_REPLACE_CLIENT" )
.addText( "" + MB_REPLACE_CLIENT );
Element detail10 = root.addElement( "NB_DRVR_LCNCE" )
.addText( "" + NB_DRVR_LCNCE );
Element detail11 = root.addElement( "NB_PHONETIC_NM" )
.addText( "" + NB_PHONETIC_NM );
Element detail12 = root.addElement( "IN_VIC_LICENCE" )
.addText( "" + IN_VIC_LICENCE );
return document;
}
}
public void write(Document document) throws IOException {
// lets write to a file
FileWriter fw = new FileWriter("output.xml"
XMLWriter writer = new XMLWriter(fw);
writer.write( document );
writer.close();
}
}
XML READER
/*
* Created on Oct 12, 2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler ;
/**
* @author Nicole
*
* used to retreive details out of XML tages
* and store them as relevant details
* to be sent to a database
*
*/
public class RetreiveData extends DefaultHandler{
public String tagStart;
public String tableName = "none";
public String[] details;
public RetreiveData ss ;
public RetreiveData(){
}
// public static void main(String[]args)
public void getData(String path)
{
try
{
Class c = Class.forName("org.apache.xerces.parsers.SAXParser"
XMLReader reader = (XMLReader)c.newInstance();
ss = new RetreiveData();
reader.setContentHandler(ss);
reader.parse(path);
}
catch(Exception e){System.out.println(e);}
}
public void startElement(String uri, String local_name, String raw_name, Attributes amap)
throws SAXException
{
//System.out.println("start " + local_name + " found "
tagStart = local_name;
if(tagStart.equalsIgnoreCase("SP0100"){
System.out.println("\tNew SP0100"
tableName = tagStart;
details = new String[12];
}
}
public void endElement(String uri, String local_name, String raw_name)
throws SAXException
{
//System.out.println("end " + local_name + " found"
if(local_name.equalsIgnoreCase("SP0100"){
System.out.println("\tEnd SP0100"
}
}
public void startDocument() throws SAXException
{
System.out.println("start document"
}
public void endDocument() throws SAXException
{
System.out.println("end document"
if(tableName.equalsIgnoreCase("none"){
System.out.println("No such Table"
}
else{
System.out.println("\n" + tableName);
for(int i = 0; i <details.length; i++){
System.out.print(details + ", "
}
new PopulateD0100B(details, tableName);
}
}
public void characters(char[] ch, int start, int length)
throws SAXException
{
if(tableName.equalsIgnoreCase("SP0100"){
if(tagStart.equalsIgnoreCase("NB_CLIENT"){
System.out.println("\t\tNB_CLIENT - " +new String(ch,start,length));
details[0]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("TY_CLIENT"){
System.out.println("\t\tTY_CLIENT - " +new String(ch,start,length));
details[1]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("TX_SRCE_ENTRY_CHNG"){
System.out.println("\t\tTX_SRCE_ENTRY_CHNG - " +new String(ch,start,length));
details[2]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("NM_OPER_MAKNG_CHNG"){
System.out.println("\t\tNM_OPER_MAKNG_CHNG - " +new String(ch,start,length));
details[3]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("DT_UPDATE"){
System.out.println("\t\tDT_UPDATE - " +new String(ch,start,length));
details[4]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("TM_UPDATE"){
System.out.println("\t\tTM_UPDATE - " +new String(ch,start,length));
details[5]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("CD_RSN_REMO_CLIENT"){
System.out.println("\t\tCD_RSN_REMO_CLIENT - " +new String(ch,start,length));
details[6]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("DT_REMOVAL_CLIENT"){
System.out.println("\t\tDT_REMOVAL_CLIENT - " +new String(ch,start,length));
details[7] = new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("MB_REPLACE_CLIENT"){
System.out.println("\t\tMB_REPLACE_CLIENT - " +new String(ch,start,length));
details[8]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("NB_PHONETIC_NM"){
System.out.println("\t\tNB_PHONETIC_NM - " +new String(ch,start,length));
details[9]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("NB_DRVR_LCNCE"){
System.out.println("\t\tNB_DRVR_LCNCE - " +new String(ch,start,length));
details[10]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("IN_VIC_LICENCE"){
System.out.println("\t\tIN_VIC_LICENCE - " +new String(ch,start,length));
details[11]= new String(ch,start,length);
}
}
tagStart="";
}
}
I have this servlet which runs on myPc at the moment and is executed via
anyway this servlet creats and XML Document.
Then i want to call another class which code iwill show below. this class reads the XML values and stores them in an array. the other class graps this infprmation and for now loops through it and displays it.
the problem is i can't seem to get the XML reader to find the file on the system.
well heres the code hope someone can help
OH AND ALSO THE DIRECTORY STRUCTURE ON MY SYSTEM IS
..\jsdk2.1 IS THE ROOT AND WHERE THE xml APPEARS
..\jsdk2.1\examples\WEB-INF\servlets THIS IS WHERE THE SERVLET AND OTHER CODE APPEARS
SERVLET
/*
*
*This servlet creates the web form through which you can insert a new record
*into the database.
*
*It will check to ensure that data is entered into all
*
*/
import java.io.*;
//import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.XMLWriter;
public class Fiddle extends HttpServlet {
public ResourceBundle rb = ResourceBundle.getBundle("LocalStrings"
public String tagStart;
public String tableName = "none";
public String[] details;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("text/html"
PrintWriter out = response.getWriter();
out.println("<html>"
out.println("<body>"
out.println("<head>"
out.println("<title>Insert Details in DB2</title>"
out.println("</head>"
out.println("<body>"
out.println("<h1>Database Input</h1>"
out.println("<table border=0><tr><td>"
out.println("<P>"
out.print("<form action=\""
out.print("Fiddle\" "
out.println("method=POST>"
out.println(rb.getString("requestparams.DB_NAME");
out.println("<input type=text size=20 name=DB_NAME>"
out.println("<br>"
out.println(rb.getString("requestparams.NB_CLIENT");
out.println("<input type=text size=20 name=NB_CLIENT>"
out.println("<br>"
out.println(rb.getString("requestparams.TY_CLIENT");
out.println("<input type=text size=20 name=TY_CLIENT>"
out.println("<br>"
out.println(rb.getString("requestparams.TX_SRCE_ENTRY_CHNG");
out.println("<input type=text size=20 name=TX_SRCE_ENTRY_CHNG>"
out.println("<br>"
out.println(rb.getString("requestparams.NM_OPER_MAKNG_CHNG");
out.println("<input type=text size=20 name=NM_OPER_MAKNG_CHNG>"
out.println("<br>"
out.println(rb.getString("requestparams.DT_UPDATE");
out.println("<input type=text size=20 name=DT_UPDATE>"
out.println("<br>"
out.println(rb.getString("requestparams.TM_UPDATE");
out.println("<input type=text size=20 name=TM_UPDATE>"
out.println("<br>"
out.println(rb.getString("requestparams.CD_RSN_REMO_CLIENT");
out.println("<input type=text size=20 name=CD_RSN_REMO_CLIENT>"
out.println("<br>"
out.println(rb.getString("requestparams.DT_REMOVAL_CLIENT");
out.println("<input type=text size=20 name=DT_REMOVAL_CLIENT>"
out.println("<br>"
out.println(rb.getString("requestparams.MB_REPLACE_CLIENT");
out.println("<input type=text size=20 name=MB_REPLACE_CLIENT>"
out.println("<br>"
out.println(rb.getString("requestparams.NB_PHONETIC_NM");
out.println("<input type=text size=20 name=NB_PHONETIC_NM>"
out.println("<br>"
out.println(rb.getString("requestparams.NB_DRVR_LCNCE");
out.println("<input type=text size=20 name=NB_DRVR_LCNCE>"
out.println("<br>"
out.println(rb.getString("requestparams.IN_VIC_LICENCE");
out.println("<input type=text size=20 name=IN_VIC_LICENCE>"
out.println("<br>"
out.println("<input type=submit>"
out.println("</form>"
out.println("</td><td>"
String DB_NAME = request.getParameter("DB_NAME"
String NB_CLIENT = request.getParameter("NB_CLIENT"
String TY_CLIENT = request.getParameter("TY_CLIENT"
String TX_SRCE_ENTRY_CHNG = request.getParameter("TX_SRCE_ENTRY_CHNG"
String NM_OPER_MAKNG_CHNG = request.getParameter("NM_OPER_MAKNG_CHNG"
String DT_UPDATE = request.getParameter("DT_UPDATE"
String TM_UPDATE = request.getParameter("TM_UPDATE"
String CD_RSN_REMO_CLIENT = request.getParameter("CD_RSN_REMO_CLIENT"
String DT_REMOVAL_CLIENT = request.getParameter("DT_REMOVAL_CLIENT"
String MB_REPLACE_CLIENT = request.getParameter("MB_REPLACE_CLIENT"
String NB_PHONETIC_NM = request.getParameter("NB_PHONETIC_NM"
String NB_DRVR_LCNCE = request.getParameter("NB_DRVR_LCNCE"
String IN_VIC_LICENCE = request.getParameter("IN_VIC_LICENCE"
out.println(rb.getString("requestparams.params-in-req" + "<br>"
out.println("<p>1</p><br>"
if (DB_NAME == null || NB_CLIENT == null || TY_CLIENT == null ||
TX_SRCE_ENTRY_CHNG == null || NM_OPER_MAKNG_CHNG == null ||
DT_UPDATE == null || TM_UPDATE == null ||CD_RSN_REMO_CLIENT == null ||
DT_REMOVAL_CLIENT == null || MB_REPLACE_CLIENT == null ||NB_PHONETIC_NM == null ||
NB_DRVR_LCNCE == null || IN_VIC_LICENCE == null)
{
out.println("<p>2</p><br>"
out.println(rb.getString("requestparams.no-params");
}
else if (DB_NAME.equals("" || NB_CLIENT.equals("" || TY_CLIENT.equals("" ||
TX_SRCE_ENTRY_CHNG.equals("" || NM_OPER_MAKNG_CHNG.equals("" ||
DT_UPDATE.equals("" || TM_UPDATE.equals("" ||CD_RSN_REMO_CLIENT.equals("" ||
DT_REMOVAL_CLIENT.equals("" || MB_REPLACE_CLIENT.equals("" ||NB_PHONETIC_NM.equals("" ||
NB_DRVR_LCNCE.equals("" || IN_VIC_LICENCE.equals("")
{
out.println("<p>2</p><br>"
out.println(rb.getString("requestparams.no-params");
}
else {
out.println("<p>3</p><br>"
out.println(rb.getString("requestparams.DB_NAME");
out.println(" = " + DB_NAME + "<br>"
out.println(rb.getString("requestparams.NB_CLIENT");
out.println(" = " + NB_CLIENT + "<br>"
out.println(rb.getString("requestparams.TY_CLIENT");
out.println(" = " + TY_CLIENT + "<br>"
out.println(rb.getString("requestparams.TX_SRCE_ENTRY_CHNG");
out.println(" = " + TX_SRCE_ENTRY_CHNG + "<br>"
out.println(rb.getString("requestparams.NM_OPER_MAKNG_CHNG");
out.println(" = " + NM_OPER_MAKNG_CHNG + "<br>"
out.println(rb.getString("requestparams.DT_UPDATE");
out.println(" = " + DT_UPDATE + "<br>"
out.println(rb.getString("requestparams.TM_UPDATE");
out.println(" = " + TM_UPDATE + "<br>"
out.println(rb.getString("requestparams.CD_RSN_REMO_CLIENT");
out.println(" = " + CD_RSN_REMO_CLIENT + "<br>"
out.println(rb.getString("requestparams.DT_REMOVAL_CLIENT");
out.println(" = " + DT_REMOVAL_CLIENT + "<br>"
out.println(rb.getString("requestparams.MB_REPLACE_CLIENT");
out.println(" = " + MB_REPLACE_CLIENT + "<br>"
out.println(rb.getString("requestparams.NB_PHONETIC_NM");
out.println(" = " + NB_PHONETIC_NM + "<br>"
out.println(rb.getString("requestparams.NB_DRVR_LCNCE");
out.println(" = " + NB_DRVR_LCNCE + "<br>"
out.println(rb.getString("requestparams.IN_VIC_LICENCE");
out.println(" = " + IN_VIC_LICENCE + "<br>"
}
out.println("</td></tr></table>"
out.println("</body>"
out.println("</html>"
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
write(createDocument(request));
RetreiveData ret = new RetreiveData();
ret.getData("output.xml/../../.."
String[] tem = ret.details;
String val;
PrintWriter out = response.getWriter();
if(tem != null){
for(int i = 0; i<tem.length;i++){
out.println("<p>"+tem+"</p><br>"
}
}
else{
out.println("no values entered"
}
doGet(request, response);
}
public Document createDocument(HttpServletRequest request) {
Document document = DocumentHelper.createDocument();
String DB_NAME = request.getParameter("DB_NAME"
String NB_CLIENT = request.getParameter("NB_CLIENT"
String TY_CLIENT = request.getParameter("TY_CLIENT"
String TX_SRCE_ENTRY_CHNG = request.getParameter("TX_SRCE_ENTRY_CHNG"
String NM_OPER_MAKNG_CHNG = request.getParameter("NM_OPER_MAKNG_CHNG"
String DT_UPDATE = request.getParameter("DT_UPDATE"
String TM_UPDATE = request.getParameter("TM_UPDATE"
String CD_RSN_REMO_CLIENT = request.getParameter("CD_RSN_REMO_CLIENT"
String DT_REMOVAL_CLIENT = request.getParameter("DT_REMOVAL_CLIENT"
String MB_REPLACE_CLIENT = request.getParameter("MB_REPLACE_CLIENT"
String NB_PHONETIC_NM = request.getParameter("NB_PHONETIC_NM"
String NB_DRVR_LCNCE = request.getParameter("NB_DRVR_LCNCE"
String IN_VIC_LICENCE = request.getParameter("IN_VIC_LICENCE"
if (DB_NAME.equals("" || NB_CLIENT.equals("" || TY_CLIENT.equals("" ||
TX_SRCE_ENTRY_CHNG.equals("" || NM_OPER_MAKNG_CHNG.equals("" ||
DT_UPDATE.equals("" || TM_UPDATE.equals("" ||CD_RSN_REMO_CLIENT.equals("" ||
DT_REMOVAL_CLIENT.equals("" || MB_REPLACE_CLIENT.equals("" ||NB_PHONETIC_NM.equals("" ||
NB_DRVR_LCNCE.equals("" || IN_VIC_LICENCE.equals("") {
Element root = document.addElement( "root" );
Element author1 = root.addElement( "author" )
.addAttribute( "name", "James" )
.addAttribute( "location", "UK" )
.addText( "James Strachan" );
Element author2 = root.addElement( "author" )
.addAttribute( "name", "Bob" )
.addAttribute( "location", "US" )
.addText( "Bob McWhirter" );
return document;
}
else {
Element root = document.addElement( "DB_NAME"
Element detail1 = root.addElement( "NB_CLIENT" )
.addText( "" + NB_CLIENT );
Element detail2 = root.addElement( "TY_CLIENT" )
.addText( "" + TY_CLIENT );
Element detail3 = root.addElement( "TX_SRCE_ENTRY_CHNG" )
.addText( "" + TX_SRCE_ENTRY_CHNG );
Element detail4 = root.addElement( "NM_OPER_MAKNG_CHNG" )
.addText( "" + NM_OPER_MAKNG_CHNG );
Element detail5 = root.addElement( "DT_UPDATE" )
.addText( "" + DT_UPDATE );
Element detail6 = root.addElement( "TM_UPDATE" )
.addText( "" + TM_UPDATE );
Element detail7 = root.addElement( "CD_RSN_REMO_CLIENT" )
.addText( "" + CD_RSN_REMO_CLIENT );
Element detail8 = root.addElement( "DT_REMOVAL_CLIENT" )
.addText( "" + DT_REMOVAL_CLIENT );
Element detail9 = root.addElement( "MB_REPLACE_CLIENT" )
.addText( "" + MB_REPLACE_CLIENT );
Element detail10 = root.addElement( "NB_DRVR_LCNCE" )
.addText( "" + NB_DRVR_LCNCE );
Element detail11 = root.addElement( "NB_PHONETIC_NM" )
.addText( "" + NB_PHONETIC_NM );
Element detail12 = root.addElement( "IN_VIC_LICENCE" )
.addText( "" + IN_VIC_LICENCE );
return document;
}
}
public void write(Document document) throws IOException {
// lets write to a file
FileWriter fw = new FileWriter("output.xml"
XMLWriter writer = new XMLWriter(fw);
writer.write( document );
writer.close();
}
}
XML READER
/*
* Created on Oct 12, 2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler ;
/**
* @author Nicole
*
* used to retreive details out of XML tages
* and store them as relevant details
* to be sent to a database
*
*/
public class RetreiveData extends DefaultHandler{
public String tagStart;
public String tableName = "none";
public String[] details;
public RetreiveData ss ;
public RetreiveData(){
}
// public static void main(String[]args)
public void getData(String path)
{
try
{
Class c = Class.forName("org.apache.xerces.parsers.SAXParser"
XMLReader reader = (XMLReader)c.newInstance();
ss = new RetreiveData();
reader.setContentHandler(ss);
reader.parse(path);
}
catch(Exception e){System.out.println(e);}
}
public void startElement(String uri, String local_name, String raw_name, Attributes amap)
throws SAXException
{
//System.out.println("start " + local_name + " found "
tagStart = local_name;
if(tagStart.equalsIgnoreCase("SP0100"){
System.out.println("\tNew SP0100"
tableName = tagStart;
details = new String[12];
}
}
public void endElement(String uri, String local_name, String raw_name)
throws SAXException
{
//System.out.println("end " + local_name + " found"
if(local_name.equalsIgnoreCase("SP0100"){
System.out.println("\tEnd SP0100"
}
}
public void startDocument() throws SAXException
{
System.out.println("start document"
}
public void endDocument() throws SAXException
{
System.out.println("end document"
if(tableName.equalsIgnoreCase("none"){
System.out.println("No such Table"
}
else{
System.out.println("\n" + tableName);
for(int i = 0; i <details.length; i++){
System.out.print(details + ", "
}
new PopulateD0100B(details, tableName);
}
}
public void characters(char[] ch, int start, int length)
throws SAXException
{
if(tableName.equalsIgnoreCase("SP0100"){
if(tagStart.equalsIgnoreCase("NB_CLIENT"){
System.out.println("\t\tNB_CLIENT - " +new String(ch,start,length));
details[0]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("TY_CLIENT"){
System.out.println("\t\tTY_CLIENT - " +new String(ch,start,length));
details[1]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("TX_SRCE_ENTRY_CHNG"){
System.out.println("\t\tTX_SRCE_ENTRY_CHNG - " +new String(ch,start,length));
details[2]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("NM_OPER_MAKNG_CHNG"){
System.out.println("\t\tNM_OPER_MAKNG_CHNG - " +new String(ch,start,length));
details[3]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("DT_UPDATE"){
System.out.println("\t\tDT_UPDATE - " +new String(ch,start,length));
details[4]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("TM_UPDATE"){
System.out.println("\t\tTM_UPDATE - " +new String(ch,start,length));
details[5]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("CD_RSN_REMO_CLIENT"){
System.out.println("\t\tCD_RSN_REMO_CLIENT - " +new String(ch,start,length));
details[6]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("DT_REMOVAL_CLIENT"){
System.out.println("\t\tDT_REMOVAL_CLIENT - " +new String(ch,start,length));
details[7] = new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("MB_REPLACE_CLIENT"){
System.out.println("\t\tMB_REPLACE_CLIENT - " +new String(ch,start,length));
details[8]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("NB_PHONETIC_NM"){
System.out.println("\t\tNB_PHONETIC_NM - " +new String(ch,start,length));
details[9]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("NB_DRVR_LCNCE"){
System.out.println("\t\tNB_DRVR_LCNCE - " +new String(ch,start,length));
details[10]= new String(ch,start,length);
}
else if(tagStart.equalsIgnoreCase("IN_VIC_LICENCE"){
System.out.println("\t\tIN_VIC_LICENCE - " +new String(ch,start,length));
details[11]= new String(ch,start,length);
}
}
tagStart="";
}
}