codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  How to search for string received from client  david4u at 17:22 on Wednesday, May 04, 2005
 

Hello Everyone,
I am just confused on how to search for strings and values received from client servlet and send back a reply as a server servlet using XML.
For examples, if I received something like this from my client servlet:

<?xml version = '1.0'?>
<!DOCTYPE AdjAmtReq SYSTEM "adj.dtd">
<AdjAmtReq>
<SubsID>564004328</SubsID>
<CardCode>4532</CardCode>
<CardAmt>12.00</CardAmt>
<LifeSpan>30</LifeSpan>
<PromoID>01</PromoID>
</AdjAmtReq>

and I want to search for all the strings and values .e g.
I want to check if <?xml version = '1.0'?> is received correcly and then the pointer should go to the next <!DOCTYPE AdjAmtReq SYSTEM "adj.dtd"> and if it is correct as it is then go to the next and also <SubsID>564004328</SubsID> ...check the value and if the values received is possitive values and it is correct then go to the next and finnally I want to print out a success answer and this is how I implemented it but I need to figure out how to use:
1. string search ....to search each string
or
2. string find or
3. if there is a better way of doing it.

This is my code below can anyone help me:

package JavaClasses;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.ObjectInputStream;
import javax.servlet.ServletException;
import javax.servlet.ServletContext;
import javax.servlet.ServletConfig;


public class SampleServlet extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
Enumeration params;
String name, value;
res.setContentType("text/xml");
PrintWriter pw = res.getWriter();

pw.println("<?xml version = \"1.0\"?>");
pw.println("<AdjResp>");
pw.println("<description>EXITO</description>");
pw.println("</AdjResp>");

params = req.getParameterNames();

while(params.hasMoreElements())
{
name = (String)params.nextElement();
String [] Values = req.getParameterValues(name);
System.out.println("\n Parameter name is " + name);

if (Values.length == 1)
{
String Value = Values[0];
if (Value.length() == 0)
pw.println("No Value");
else
pw.println(Value);
}
else
{
pw.println("There is nothing to be printed");
for(int i= 0; i<Values.length; i++)
{
pw.println("Value: " + Values);
System.out.println("The Value is: " + Values);

}
pw.println("It is done");
pw.println("<P>Parameter name is: <EM>" + name + "</EM>");
pw.println("<P>Parameter value is: <EM>" + Values + "</EM>");


}

}

}

public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
doGet(req, res);
}

}

I am using tomcat5.5 server
Looking forward to your explanations pls.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  How to search for string received from client
•  How to search for string received from client
•  CheckBox`s Validation Thru Database...!
•  Re: Deleting from database (ms. Access)
•  APIs to convert file format
•  onreadystatechange help
•  Re: Help me !!
•  Re: The .Net Data SQL Provider (System.Data.SqlClient) requires Microsoft Data Access Components(MDAC) version 2.6 or later.
•  Re: What won`t this work?


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005