473,672 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to do checking of the value

149 New Member
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 916

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

Similar topics

0
1473
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 help ensure correct behavior in a concurrent environment. That's impressive. That's *really* impressive. I know of no other language that does that - though they probably exist. I'd be interested in references to them. Normally, I think of...
99
5132
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
2
3707
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 */ } else { /* exit with error message */
4
6052
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, just incase, I want to check that the selected value actually exists as a value in the dropDownList before I actually try to select it. I've tried this:
4
8956
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
2374
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 exceptions?
5
2647
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 Me.DetailsView1.Fields.Item(6) = True Then 'do something End If
1
1195
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 database fields dx or dy? & Pid & Pid2 is Value to compare ? This code is working fine ?
3
8855
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 that I call from the visible property of the gridview itemtemplate, the textbox is always blank. I tried setting the textbox in the prerender, but I suspect the
173
8085
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. OTOH, if you're allocating a gigabyte for a large array, this might fail, so you should definitely check for a NULL return.
0
8487
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8611
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6240
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5708
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4230
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2821
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1819
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.