Whats wrong with this code

admin

Administrator
Staff member
Hi there,Viji here please find out what is the error in the following code.thisis a servlet which i am calling after submiting a button and if we want wecan redirect it to some other html file using response.sendRedirect("xxx.html");but the error is coming ie "page can not be displayed"help in this regard thankx.Viji.import java.util.*;import javax.servlet.http.*;import javax.servlet.*;import java.io.*;import java.net.*;import com.sun.xml.tree.*;public class XMLBuild extends HttpServlet {public void init(ServletConfig config) throws ServletException {super.init(config);}public void doPost(HttpServletRequest req, HttpServletResponse res) throwsServletException, IOException {res.setContentType("text/html");PrintWriter out = res.getWriter();try{HttpSession session = req.getSession(true);XmlDocument doc = new XmlDocument ();////////////////////////////////////////////////String fname = "";String mi = "";String lname = "";String add1 = "";String add2 = "";String city1 = "";String state_id = "";String country_id = "";String email1 = "";String zip1 = "";String cctype = "";String cardnumber = "";String expirationmonth = "";String expirationyear = "";String ssn_1 = "";String ssn_2 = "";String ssn_3 = "";String npa_1 = "";String nxx_1 = "";String line_1 = "";/////////////////////STRING DEFINITIONS////////fname = req.getParameter("fname");fname = fname != null ? fname : "";mi = req.getParameter("mi");mi = mi != null ? mi : "";lname = req.getParameter("lname");lname = lname != null ? lname : "";add1 = req.getParameter("add1");add1 = add1 != null ? add1 : "";add2 = req.getParameter("add2");add2 = add2 != null ? add2 : "";city1 = req.getParameter("city");city1 = city1 != null ? city1 : "";state_id = req.getParameter("state");state_id = state_id != null ? state_id : "";email1 = req.getParameter("email");email1 = email1 != null ? email1 : "";zip1 = req.getParameter("zip");zip1 = zip1 != null ? zip1 : "";cctype = req.getParameter("cctype");cctype = cctype != null ? cctype : "";cardnumber = req.getParameter("ccnum");cardnumber = cardnumber != null ? cardnumber : "";expirationmonth =req.getParameter("expmonth");expirationmonth = expirationmonth != null ? expirationmonth : "";expirationyear =req.getParameter("expyear");expirationyear = expirationyear != null ? expirationyear : "";ssn_1 =req.getParameter("ssn1");ssn_1 = ssn_1 != null ? ssn_1 : "";ssn_2 =req.getParameter("ssn2");ssn_2 = ssn_2 != null ? ssn_2 : "";ssn_3 =req.getParameter("ssn3");ssn_3 = ssn_3 != null ? ssn_3 : "";npa_1 =req.getParameter("npa");npa_1 = npa_1 != null ? npa_1 : "";nxx_1 =req.getParameter("nxx");nxx_1 = nxx_1 != null ? nxx_1 : "";line_1 =req.getParameter("line");line_1 = line_1 != null ? line_1 : "";//////////////////////////////////////////////////ElementNode batch = (ElementNode)doc.createElement("batch");doc.appendChild(batch);ElementNode feed_id = (ElementNode)doc.createElement("feed_id");feed_id.setAttribute ("feed_type", "complete");batch.appendChild(feed_id);feed_id.appendChild(doc.createTextNode("testtust1"));ElementNode source = (ElementNode)doc.createElement("source");batch.appendChild(source);ElementNode partner = (ElementNode)doc.createElement("partner");ElementNode site = (ElementNode)doc.createElement("site");ElementNode banner = (ElementNode)doc.createElement("banner");source.appendChild(partner);partner.appendChild(doc.createTextNode("GetSponsor"));source.appendChild(site);site.appendChild(doc.createTextNode("Getsponsor.com"));source.appendChild(banner);banner.appendChild(doc.createTextNode("abcd.gif"));ElementNode order = (ElementNode)doc.createElement("order");batch.appendChild(order);ElementNode order_num = (ElementNode)doc.createElement("order_num");order.appendChild(order_num);order_num.appendChild(doc.createTextNode("pp00005"));ElementNode customer = (ElementNode)doc.createElement("customer");order.appendChild(customer);ElementNode name = (ElementNode)doc.createElement("name");customer.appendChild(name);ElementNode first = (ElementNode)doc.createElement("first");name.appendChild(first);//first.appendChild(doc.createTextNode("Ajay"));first.appendChild(doc.createTextNode(fname));ElementNode middle = (ElementNode)doc.createElement("middle");name.appendChild(middle);middle.appendChild(doc.createTextNode(mi));ElementNode last = (ElementNode)doc.createElement("last");name.appendChild(last);//last.appendChild(doc.createTextNode("Kumar"));last.appendChild(doc.createTextNode(lname));/////////////////////////////////////ElementNode address = (ElementNode)doc.createElement("address");customer.appendChild(address);ElementNode street1 = (ElementNode)doc.createElement("street1");address.appendChild(street1);//street1.appendChild(doc.createTextNode("Bayshore Road"));street1.appendChild(doc.createTextNode(add1));ElementNode street2 = (ElementNode)doc.createElement("street2");address.appendChild(street2);//street2.appendChild(doc.createTextNode("Suite 100"));street2.appendChild(doc.createTextNode(add2));ElementNode city = (ElementNode)doc.createElement("city");address.appendChild(city);//city.appendChild(doc.createTextNode("Palo Alto"));city.appendChild(doc.createTextNode(city1));ElementNode state = (ElementNode)doc.createElement("state");address.appendChild(state);//state.appendChild(doc.createTextNode("California"));state.appendChild(doc.createTextNode(state_id));ElementNode zip = (ElementNode)doc.createElement("zip");address.appendChild(zip);ElementNode code = (ElementNode)doc.createElement("code");zip.appendChild(code);//code.appendChild(doc.createTextNode("94303"));code.appendChild(doc.createTextNode(zip1));ElementNode plus4 = (ElementNode)doc.createElement("plus4");zip.appendChild(plus4);plus4.appendChild(doc.createTextNode("2003"));////////////////////////////////////ElementNode phone = (ElementNode)doc.createElement("phone");customer.appendChild(phone);ElementNode npa = (ElementNode)doc.createElement("npa");phone.appendChild(npa);npa.appendChild(doc.createTextNode(npa_1));ElementNode nxx = (ElementNode)doc.createElement("nxx");phone.appendChild(nxx);nxx.appendChild(doc.createTextNode(nxx_1));ElementNode line = (ElementNode)doc.createElement("line");phone.appendChild(line);line.appendChild(doc.createTextNode(line_1));ElementNode email = (ElementNode)doc.createElement("email");customer.appendChild(email);//email.appendChild(doc.createTextNode("[email protected]"));email.appendChild(doc.createTextNode(email1));/////////////////////////////////////////////////////ElementNode ssn = (ElementNode)doc.createElement("ssn");customer.appendChild(ssn);ElementNode ssn1 = (ElementNode)doc.createElement("ssn1");ssn.appendChild(ssn1);ssn1.appendChild(doc.createTextNode(ssn_1));ElementNode ssn2 = (ElementNode)doc.createElement("ssn2");ssn.appendChild(ssn2);ssn2.appendChild(doc.createTextNode(ssn_2));ElementNode ssn3 = (ElementNode)doc.createElement("ssn3");ssn.appendChild(ssn3);ssn3.appendChild(doc.createTextNode(ssn_3));ElementNode order_items = (ElementNode)doc.createElement("order_items");order.appendChild(order_items);ElementNode sku = (ElementNode)doc.createElement("sku");order_items.appendChild(sku);sku.setAttribute ("quantity", "1");sku.appendChild(doc.createTextNode("oro7_3po"));ElementNode order_data = (ElementNode)doc.createElement("order_data");order.appendChild(order_data);ElementNode ld_carrier = (ElementNode)doc.createElement("ld_carrier");order_data.appendChild(ld_carrier);ld_carrier.setAttribute ("att", "att");ld_carrier.setAttribute ("switch_to_att", "yes");ElementNode credit_card = (ElementNode)doc.createElement("credit_card");order_data.appendChild(credit_card);credit_card.setAttribute ("card_type", "visa");ElementNode card_data = (ElementNode)doc.createElement("card_data");order_data.appendChild(card_data);ElementNode number = (ElementNode)doc.createElement("number");card_data.appendChild(number);number.appendChild(doc.createTextNode("1234567890"));ElementNode expiration = (ElementNode)doc.createElement("expiration");card_data.appendChild(expiration);ElementNode month = (ElementNode)doc.createElement("month");expiration.appendChild(month);month.appendChild(doc.createTextNode("01"));ElementNode year = (ElementNode)doc.createElement("month");expiration.appendChild(year);year.appendChild(doc.createTextNode("2001"));////////////////////////////////////////////////////////ElementNode billing_data = (ElementNode)doc.createElement("billing_data");order_data.appendChild(billing_data);ElementNode bill_name = (ElementNode)doc.createElement("bill_name");billing_data.appendChild(bill_name);ElementNode bill_fname = (ElementNode)doc.createElement("bill_fname");bill_name.appendChild(bill_fname);//bill_fname.appendChild(doc.createTextNode("JOHN"));bill_fname.appendChild(doc.createTextNode(fname));ElementNode bill_mi = (ElementNode)doc.createElement("bill_mi");bill_name.appendChild(bill_mi);bill_mi.appendChild(doc.createTextNode(mi));ElementNode bill_lname = (ElementNode)doc.createElement("bill_lname");bill_name.appendChild(bill_lname);//bill_lname.appendChild(doc.createTextNode("K"));bill_lname.appendChild(doc.createTextNode(lname));ElementNode bill_address = (ElementNode)doc.createElement("bill_address");billing_data.appendChild(bill_address);ElementNode bill_street1 = (ElementNode)doc.createElement("bill_street1");bill_address.appendChild(bill_street1);//bill_street1.appendChild(doc.createTextNode("Bayshore Road"));bill_street1.appendChild(doc.createTextNode(add1));ElementNode bill_street2 = (ElementNode)doc.createElement("bill_street2");bill_address.appendChild(bill_street2);//bill_street2.appendChild(doc.createTextNode("Suite 100"));bill_street2.appendChild(doc.createTextNode(add2));ElementNode bill_city = (ElementNode)doc.createElement("bill_city");bill_address.appendChild(bill_city);//bill_city.appendChild(doc.createTextNode("Palo Alto"));bill_city.appendChild(doc.createTextNode(city1));ElementNode bill_state = (ElementNode)doc.createElement("bill_state");bill_address.appendChild(bill_state);//bill_state.appendChild(doc.createTextNode("CA"));bill_state.appendChild(doc.createTextNode(state_id));ElementNode bill_zip = (ElementNode)doc.createElement("bill_zip");bill_address.appendChild(bill_zip);ElementNode bill_code = (ElementNode)doc.createElement("bill_code");bill_zip.appendChild(bill_code);//bill_code.appendChild(doc.createTextNode("07738"));bill_code.appendChild(doc.createTextNode(zip1));ElementNode bill_plus4 = (ElementNode)doc.createElement("bill_plus4");bill_zip.appendChild(bill_plus4);bill_plus4.appendChild(doc.createTextNode("2003"));session.putValue("XmlObject",doc);//res.sendRedirect("../E-Cards.html");}catch(Exception e){//res.sendRedirect("/CardInfo.html");}//out.close();res.sendRedirect("/E-Cards.html");}}
 
Back
Top