I want to execute a SQL query in JSP. The display should be in JSP code, not in Java.
I can not present the JSP code in the Java page.
package tn.com.tradenet.utilisateur; Import java.io.IOException; Import java.io.printWriter; Import java.sql.Connection; Import java.sql.PreparedStatement; Import java.sql.ResultSet; Import java.sql.SQLException; Import java.sql.Statement; Import javax.servlet.RequestDispatcher; Import javax.servlet.ServletException; Import javax.servlet.http.httpServlet; Import javax.servlet.http.HttpServletRequest; Import javax.servlet.http.HttpServletResponse; Import javax.servlet.http.http.http session; Public class revision HttpServlet {public void doPost () {{string id = "1"; //request.getParameter("userName "); String name = "maple"; //request.getParameter("userName "); String perenam = "phazia"; //request.getParameter("userName "); String email = "hotmail"; //request.getParameter("password "); String Profile = "Fozia"; //request.getParameter("password "); String login = "fozia"; //request.getParameter("password "); String pass = "1258"; //request.getParameter("password "); ConnectionBD mod = new connectionBD (); // string sql = "user ID selected"; // ResultSet res = mod.execMonSQl (SQL); // while (res.next ()) // {// id = res.getString (1); // mod.execMonUpdate ("UPDATE Utility SET nom = '" + nom + "', prenom = '" + prenom + "', email = '" + + email + "', profile = '" + profile + "' , Login = '"+ login +"', pass = '"+ pass +"' WHERE 'id' = '"+ id +"' '); System.out.println ("element unknowns");} cache Eclipse (s) {System.out.println ("error" + S);}} public static zero main (string [] args) {modification mdf = new modification (); mdf.doPost ();} < / Pre>
You must override the actual method, not to add another , Which Late will not be used by the container. @Override secures zero doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// Your work is here} and you need to map this servlet to the web.xml on a known URL pattern. gt; & lt; Servlet-name & gt; modification & lt; / Servlet-name & gt; & Lt; Servlet category & gt; Com.example.Modification & lt; / Servlet category & gt; & Lt; / Servlet & gt; & Lt; Servlet-mapping & gt; & Lt; Servlet-name & gt; Research & lt; / Servlet-name & gt; & Lt; URL pattern & gt; & Lt; / revision / Url pattern & gt; & Lt; / Servlet-mapping & gt; The above and lt; Url-pattern & gt; With the the servlet will listen on the URL. Finally, the HTML Form Action URL has its JSP so that it matches the sublet URL.
& lt; Form action = "modification" method = "post" & gt; See also: - - How the servlet works and the little Hello World
No related questions / problem, note that you need to change your सर्वो SSL code to display some results pages in JSP's taste. E.g. request.getRequestDispatcher ("/ WEB-INF / result.jsp"). Forwarded (request, response); In addition, inside the servlet, the main () method does not make any sense, remove it last but not least, your SQL approach is sensitive. .
Comments
Post a Comment