1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String localactuelle= request.getParameter("nom");
String nouvelleCapacite = request.getParameter("capacite");
SAXBuilder sxb=new SAXBuilder();
Document document = null;
document = sxb.build(new File("test.xml"));
Element enteprises=document.getRootElement();
if(entreprise.getChild("local").getText().equals(localactuelle)){
entreprise.getChild("capatite").setText(nouvelleCapacite);
}
XMLOutputter xmlOutput= new XMLOutputter(Format.getPrettyFormat());
xmlOutput.output(document, new FileOutputStream("test.xml"));
getServletContext().getRequestDispatcher("/Acceuil.jsp").forward(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
getServletContext().getRequestDispatcher("/Acceuil.jsp").forward(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} |