hi,
in my project...i had used jsp pages..if i enter value in jsp page..it should match with the parameter passed in servlet...and if it is checked it should do process...my project includes xml file..im not getting validated..can any one help me out..if that 'packName' is equal then only it should do deletion otherwise it should show me the message...here is my code
delete.jsp
<td></td> <td><font color="#800000"> </font><font color="#800000"><b>Pack Name</b></font><font color="#800000" size=""> </font></td> <td><input name="packName" type="text" id="packName"> </td> <td></td>
delete.java
package proj; import java.io.*; import java.io.IOException; import java.io.PrintWriter; import java.util.Properties; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.w3c.dom.*; import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; public class delete extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter pw = response.getWriter(); String s = null; String packName = request.getParameter("packName"); try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = builderFactory.newDocumentBuilder(); // Creating the path for XML File using Properties ServletContext servletContextObj = request.getSession().getServletContext(); String excelTemplatesPath = servletContextObj.getRealPath("/"); String filePaths = excelTemplatesPath + File.separator + "config.properties"; Properties propObj = new Properties(); propObj.load(new FileInputStream(filePaths)); String gprsLoginPath = null; gprsLoginPath = propObj.getProperty("GPRS_LOGIN_PATH"); if (gprsLoginPath == null || gprsLoginPath.trim().equals("")) { gprsLoginPath = excelTemplatesPath; } gprsLoginPath += File.separator + "login.xml"; java.io.File file = new java.io.File(gprsLoginPath); Document doc = null; if (file.exists()) { try { doc = docBuilder.parse(file); } catch (Exception ex) { doc = docBuilder.newDocument(); Element root = doc.createElement("PACKS"); doc.appendChild(root); } } else { doc = docBuilder.newDocument(); // Creating Root Tag Element root = doc.createElement("PACKS"); doc.appendChild(root); } // creating a new instance of a DOM to build a DOM tree. // Document doc = docBuilder.newDocument(); delNode(file, doc, "PACK_NAME"); pw.println("<b>Xml File Deleted Successfully</b>"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); } } public static void delNode(java.io.File file, Node parent, String filter) throws Exception { NodeList children = parent.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { if (child.getNodeName().equals(filter)) { parent.removeChild(child); } else { delNode(file, child, filter); } } } // TransformerFactory instance is used to create Transformer objects. TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // create string from xml tree StringWriter sw = new StringWriter(); StreamResult result = new StreamResult(sw); //Document doc = null; DOMSource source = new DOMSource(parent); transformer.transform(source, result); String xmlString = sw.toString(); //File file = new File("E:/xgprs/xmlgprs/login.xml"); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(file))); bw.write(xmlString); bw.flush(); bw.close(); } }
thanks in advance..waiting for the reply..