aspose file tools*
The moose likes Servlets and the fly likes Could somebody give some ideas? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Could somebody give some ideas?" Watch "Could somebody give some ideas?" New topic
Author

Could somebody give some ideas?

janet ilieva
Greenhorn

Joined: Feb 02, 2001
Posts: 11
I wrote several servlets in the first(main), I have:
insert
report
delete
When your choice is insert you insert employes data like, name, birthdate and SSN.
When your choice is report you will see the all employe data.
My problem is in the process_delete. I wrote the delete servlet I put input type = "checkbox" and input type = "submit" value="Delete".When I use del servlet and choice to delete some employe data I click the delete button and he submit the information to process_delete and here is the problem because I don't no how to put this in my code process_servlet.
My del servlet :
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.ServletInputStream.*;
public class del extends HttpServlet
{
public void doGet (
HttpServletRequest request,
HttpServletResponse response
) throws ServletException, IOException
{
PrintWriter out;
response.setContentType("text/html");
out = response.getWriter();
try {
FileReader file1 = new FileReader("c:\\s_test\\data.txt");
BufferedReader buff = new BufferedReader(file1);
out.println("<HTML><BODY>");
out.println("<Page for delete"> );
out.println("<table border=\"1\" width=\"100%\">");
out.println("<Form action=\"http://localhost/servlets/process_del\"method=GET>");
out.println("<tr>");
out.println("<td width=\"25%\">NAME</td>");
out.println("<td width=\"25%\">SSN</td>");
out.println("<td width=\"25%\">BIRTHDATE</td></tr>");
out.println("<td><input type=\"reset\" Value=\"Cancel\" name=\"B2\"></tr>");
out.println("<td><input type=\"submit\" Value=\"Delete\" name=\"B2\"></tr>");
String data_line = new String(buff.readLine());
while ((data_line = buff.readLine()) != null) {
String name1 = data_line.substring(0,20).trim();
String SSN1 = data_line.substring(20,30).trim();
String birthdate1= data_line.substring(30).trim();
out.println("<tr>");
out.println("<td width=\"25%\"><input type=\"checkbox\" name=\"C1\" value=\"on\"></td>");
out.println("<td>"+ name1 + "<td>" + SSN1 + "<td>" + birthdate1 + "</td></td></td></tr>");
}
out.println("</table>");
out.println("</FORM>");
out.println("<BODY>");
out.println("</HTML>");
buff.close();
}catch (IOException e) {
//-------ERROR---------
out.println("<HTML><BODY>");
out.println(e.getMessage());
out.println("<br> :<ahref+\"http://localhost/servlets/main\">");
out.println("Go to main");
out.println("</a>");
out.println("</HTML></BODY>");
}
// then--------------
out.close();
}
}
The problem is in the process_del servlet where I have to define this process when your option is delete somebody from the table.
Thanks in advance.

Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Hello Janet,
A couple of comments first. The way you are reading in data.txt
String data_line = new String(buff.readLine());
while ((data_line = buff.readLine()) != null) {
Means that the first line in the file is never added to the output. I don't know if this is the expected behavior or not, I just figured I'd better point that out. If you want the first line simply change this to
String data_line = "";
while ((data_line = buff.readLine()) != null) {

Now for the question you had. I'm going to talk through this problem using psydo-code in the manner I would solve this.
1) get the parameter C1 from the request object
2) get the parameter C2 from the request object
3) if the C2 is equal to cancel create a request dispatch and forward the request to main
4) open the data.txt file
5) read in data.txt fully into a Vector
6) close the data.txt
7) open data.txt as a Writer(this will clear data.txt)
8) write any element in the Vector that did not equal c1 to data.txt
9) close data.txt
10) create a request dispatcher and forward the request to main.
Done.


------------------
Hope This Helps
Carl Trusiak, SCJP2
[This message has been edited by Carl Trusiak (edited June 28, 2001).]


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could somebody give some ideas?
 
Similar Threads
servlet help me
help me servlet
servlet process_delete
Servlet becomming slow
Servlet becomming slow