473,436 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,436 software developers and data experts.

how to do checking of the value

149 100+
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

Expand|Select|Wrap|Line Numbers
  1. <td></td>
  2.                         <td><font color="#800000">&nbsp;</font><font color="#800000"><b>Pack Name</b></font><font color="#800000" size="">&nbsp;</font></td>
  3.                         <td><input name="packName" type="text" id="packName"> </td>
  4.                         <td></td>
  5.  
  6.  
delete.java

Expand|Select|Wrap|Line Numbers
  1.  
  2. package proj;
  3.  
  4. import java.io.*;
  5. import java.io.IOException;
  6. import java.io.PrintWriter;
  7. import java.util.Properties;
  8. import javax.servlet.*;
  9. import javax.servlet.http.*;
  10. import javax.servlet.ServletException;
  11. import javax.servlet.http.HttpServlet;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14.  
  15. import org.w3c.dom.*;
  16. import javax.xml.parsers.*;
  17. import javax.xml.transform.*;
  18. import javax.xml.transform.dom.*;
  19. import javax.xml.transform.stream.*;
  20.  
  21. public class delete extends HttpServlet {
  22.  
  23.     public void doPost(HttpServletRequest request, HttpServletResponse response)
  24.             throws ServletException, IOException {
  25.  
  26.         response.setContentType("text/html");
  27.         PrintWriter pw = response.getWriter();
  28.         String s = null;
  29.         String packName = request.getParameter("packName");
  30.  
  31.         try {
  32.             DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
  33.             DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
  34.  
  35.             // Creating the path for XML File using Properties
  36.             ServletContext servletContextObj = request.getSession().getServletContext();
  37.             String excelTemplatesPath = servletContextObj.getRealPath("/");
  38.             String filePaths = excelTemplatesPath + File.separator
  39.                     + "config.properties";
  40.             Properties propObj = new Properties();
  41.             propObj.load(new FileInputStream(filePaths));
  42.             String gprsLoginPath = null;
  43.             gprsLoginPath = propObj.getProperty("GPRS_LOGIN_PATH");
  44.             if (gprsLoginPath == null || gprsLoginPath.trim().equals("")) {
  45.                 gprsLoginPath = excelTemplatesPath;
  46.             }
  47.             gprsLoginPath += File.separator + "login.xml";
  48.             java.io.File file = new java.io.File(gprsLoginPath);
  49.             Document doc = null;
  50.             if (file.exists()) {
  51.                 try {
  52.                     doc = docBuilder.parse(file);
  53.                 } catch (Exception ex) {
  54.                     doc = docBuilder.newDocument();
  55.                     Element root = doc.createElement("PACKS");
  56.                     doc.appendChild(root);
  57.                 }
  58.             } else {
  59.                 doc = docBuilder.newDocument();
  60.                 // Creating Root Tag
  61.                 Element root = doc.createElement("PACKS");
  62.                 doc.appendChild(root);
  63.             }
  64.  
  65.             // creating a new instance of a DOM to build a DOM tree.
  66.             // Document doc = docBuilder.newDocument();
  67.             delNode(file, doc, "PACK_NAME");
  68.             pw.println("<b>Xml File Deleted Successfully</b>");
  69.         } catch (Exception e) {
  70.             System.out.println(e);
  71.             e.printStackTrace();
  72.         }
  73.     }
  74.  
  75.     public static void delNode(java.io.File file, Node parent, String filter)
  76.             throws Exception {
  77.  
  78.         NodeList children = parent.getChildNodes();
  79.  
  80.         for (int i = 0; i < children.getLength(); i++) {
  81.             Node child = children.item(i);
  82.  
  83.             if (child.getNodeType() == Node.ELEMENT_NODE) {
  84.  
  85.                 if (child.getNodeName().equals(filter)) {
  86.                     parent.removeChild(child);
  87.                 } else {
  88.                     delNode(file, child, filter);
  89.                 }
  90.             }
  91.         }
  92.         // TransformerFactory instance is used to create Transformer objects.
  93.         TransformerFactory factory = TransformerFactory.newInstance();
  94.         Transformer transformer = factory.newTransformer();
  95.         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
  96.         // create string from xml tree
  97.         StringWriter sw = new StringWriter();
  98.         StreamResult result = new StreamResult(sw);
  99.         //Document doc = null;
  100.         DOMSource source = new DOMSource(parent);
  101.         transformer.transform(source, result);
  102.         String xmlString = sw.toString();
  103.  
  104.         //File file = new File("E:/xgprs/xmlgprs/login.xml");
  105.         BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
  106.                 new FileOutputStream(file)));
  107.         bw.write(xmlString);
  108.         bw.flush();
  109.         bw.close();
  110.  
  111.     }
  112. }
  113.  
i need help where is wrong in my code

thanks,
madhu
Jul 21 '10 #1
0 910

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mike Meyer | last post by:
The recent thread on threads caused me to reread the formal definition of SCOOP, and I noticed something I hadn't really impressed me the first time around: it's using staticly checkable rules to...
99
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
2
by: Marlene Stebbins | last post by:
I am entering numbers into my program from the command line. I want to check whether they are > INT_MAX. Sounds simple, but I've discovered that if(x <= INT_MAX) { /* use x in some calculation...
4
by: Darrel | last post by:
I'm trying to add an extra layer of error checking on a Drop Down List. The list is populated from one table, and then I select the selectedValue from another DB. While it SHOULDN'T ever happen,...
4
by: deko | last post by:
Basic question about checking the value of Toggle/Check/Combo/OptionGroups.... Checking like this: If Me!chkCheckBox Then ... End If and like this:
4
by: Patient Guy | last post by:
Does anyone have any coding rules they follow when doing argument checking? When arguments fail during check, do you return from the call with an ambiguous return value, or do you throw...
5
by: Skip | last post by:
Hi All, I am trying to check a fields value (boolean in this case) in the ItemUpdated event. The following does not work. I am very new to .NET (VB6 guy) so sorry if this is way off. If...
1
Fary4u
by: Fary4u | last post by:
"Select * from webaddress where dx='" & pid &"' and dy=" & pid2 for checking values using ASP & MS ACCESS Database that record already in Database Field or NOT? the following field are...
3
by: jc | last post by:
Hello. I have a gridview column item that i want to not make visible if the bound data in that cell is less than a value in a textbox. However, I notice at the time my code checks a function...
173
by: Marty James | last post by:
Howdy, I was reflecting recently on malloc. Obviously, for tiny allocations like 20 bytes to strcpy a filename or something, there's no point putting in a check on the return value of malloc....
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.