Hi,
I have a servlet code that saves data input from a form in HTML into a serial file. For example, I've input as following:
First Name: John
Last Name: Doe
Address: First Avenue 11111 New York
Then, I want to read this input again, by giving in only the first name or the last name. So, if I input "Doe", I will be able to see his first name and his address. This is my problem.
I know it may not be recommmended, but I'm in such a desperate mode that I want to give you the complete code (but I don't think it's long). Here is the code that saves data (write) and runs perfectly for that purpose, but I want to do the exact opposite (read):
The serial file is Adressen.ser, and my serial class is serHandler, and it has load method (with readObject) and save method (with writeObject).
I'm totally lost, and would be very appreciated for any clue!
Thanks,
Andre
I have a servlet code that saves data input from a form in HTML into a serial file. For example, I've input as following:
First Name: John
Last Name: Doe
Address: First Avenue 11111 New York
Then, I want to read this input again, by giving in only the first name or the last name. So, if I input "Doe", I will be able to see his first name and his address. This is my problem.
I know it may not be recommmended, but I'm in such a desperate mode that I want to give you the complete code (but I don't think it's long). Here is the code that saves data (write) and runs perfectly for that purpose, but I want to do the exact opposite (read):
Code:
// here bunch of import commands...
public class AdressenEingabe extends HttpServlet {
String anfrage;
String adressFileName = "./htdocs/JavaServer/Adressen.ser";
PrintWriter out;
Vector adressen;
DateiAusgabe logger;
SerHandler serializer;
HtmlWrapper wrapper;
Adresse adresse;
public void init(ServletConfig config) throws ServletException {
super.init(config);
logger = new DateiAusgabe("./logs/AdressenServlet.log");
logger.setDatumFormat(DateFormater.getTimeFormat(new Date(), null));
logger.setLogLevel(AusgabeFormat.DEBUG);
serializer = new SerHandler(logger);
adressen = (Vector)serializer.load(adressFileName);
if (adressen == null) adressen = new Vector();
}
public void destroy() {
serializer.save(adressFileName, adressen);
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
out = res.getWriter();
wrapper = new HtmlWrapper(out, getServletConfig());
if (req.getQueryString() != null) {
adresse = new Adresse(req);
adressen.add(adresse);
serializer.save(adressFileName, adressen);
}
wrapper.wrapMessage("Result", adressen.toString());
}
public void doPost (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doGet(req, res);
}
}
I'm totally lost, and would be very appreciated for any clue!
Thanks,
Andre