Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

deleting basing on action whting the same servlet

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey there , i just begun learning java EE dev , i started by trying to creat a simple inventory management apps
everything worked fine until i was trying to delete items using the servlet , so when i enter the first items prorieties it shows up ,and i can delete it , but if want to enter more
the submit button does the delete operation ! so i v been stucked in this point for long time triying to resolve it , and finnally i m calling for your help , which for i will be very gratfull !
her is my code
the jsp :
<body>
<%
ProprioBeans proprio ;
if (request.getAttribute("modele") != null ) {
proprio =(ProprioBeans)request.getAttribute("modele");

}
else {
proprio =new ProprioBeans();
}
%>

<h1>
gestion d'affaires expropriation
</h1>
<h3>Ajouter un proprietaire</h3>
<form action ="propserv" method="post">
<table border="1" width="50%">
<tr>
<td> Nom</td>
<td><input type="text" name="nom" /> </td>
</tr>

<tr>
<td>Prenom </td>
<td><input type="text" name="prenom" /> </td>
</tr>
<tr>
<td>MontantEvalue </td>
<td><input type="text" name="montant" /> </td>
</tr>
<tr>
<td>Reaction </td>
<td> <input type="text" name="reac" /></td>
</tr>
<tr > <td colspan="2"> <input type="submit" value="valider" /> </td> </tr>


</table>
<table border="1" width="60%">
<tr>
<th> Id</th>
<th>nom</th>
<th>prenom </th>
<th>montant </th>
<th>reac </th>
<th> Option </th>
</tr>
<%
Iterator<Proprio> list =proprio.getListe().iterator();
while (list.hasNext()){
Proprio p =list.next();


%>

<tr>

<td> <%= p.getId() %> </td>
<td><%= p.getNom()%> </td>
<td><%= p.getPrenom() %> </td>
<td><%= p.getMontant() %> </td>
<td><%= p.getReac() %></td>
<td>

<form action="propserv" method="post" >
<input type="hidden" name="id" value="<%=p.getId() %>" />
<input type="hidden" name="action" value="supprimer" />
<input type="submit" value="supprimer" />
</form>

</td>

</tr>
<% } %>

</table>

</form>


</body>
</html>

the servlet :
package web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;




import metier.Operation;
import metier.Proprio;


public class ProprioServlet extends HttpServlet {
private Operation op;


@Override
public void init() throws ServletException {
op = new Operation();
}


@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {

if( req.getParameter("action") != null ) {;

op.remove(Long.parseLong(req.getParameter("id")));
ProprioBeans pb = new ProprioBeans();
pb .setListe(op.getAll());
req.getRequestDispatcher("proprio.jsp").forward(req, resp);
System.out.println("action = supprimer " +req.getParameter("id"));
}else {



//recuperer les données
String nom = req.getParameter("nom");
String prenom = req.getParameter("prenom");
String montant = req.getParameter("montant");
String reac = req.getParameter("reac");

//creation des objets


ProprioBeans pb =new ProprioBeans();
//traitement
op.add(new Proprio(1L ,nom,prenom,montant, reac));
pb.setListe(op.getAll());
req.setAttribute("modele", pb);
req.getRequestDispatcher("proprio.jsp").forward(req, resp);


}

}
}

 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry, did you mention what and where did you face the problem?
And UseCodeTags <- (go through this link)
whenever you are posting any code. It will make you code more readable.
Anyway you need to remove the scriplet from JSP. They are obsolete since about 13 years now. Use EL instead.
 
yassine yakine
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah , you are right about the scriptlet , i think the tutorial i chosed to follow was obsolete too , thanks a lot for your reply ! and if you have any link for a tutorial from which i can truly learn java EE please share ;
thanks again
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I have not learnt from tutorials, so not sure. But I think Oracle's site is a good place to start with.
And specific to EL, this is the direct link in Oracle.
 
yassine yakine
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok , tanks a lot !!
 
Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic