Sunday, 15 May 2011

java - JSP Form to get customer feedback with Servlet -



java - JSP Form to get customer feedback with Servlet -

i have developed basic form using netbeans getting client input. have index.jsp file has html code, servlet values form , java class found db connection , populate db. have run on tomcat server, getting http 500 error.

here index.jsp

class="snippet-code-html lang-html prettyprint-override"><%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>feedback form personal business relationship users</title> </head> <body> <form name = "feedbackform" action="submituser" method ="post"> <p id="questions">your comments: </p> <textarea id="selection" rows="4" cols="100" name="comment"> </textarea> <br> <br> <input type = "submit" name ="sub" value="submit"> </form> </body> </html>

java class database connection

package feedback;

package feedback; import java.sql.*; import java.util.logging.level; import java.util.logging.logger; public class dbconnection { private string driver = "com.mysql.jdbc.driver"; private string url = "jdbc:mysql://localhost:3306/online_feedback"; private connection con; private statement st; private int i; public void connectdb(){ seek { class.forname(driver); con = drivermanager.getconnection(url, "root", ""); } grab (classnotfoundexception ex) { logger.getlogger(dbconnection.class.getname()).log(level.severe, null, ex); } grab (sqlexception ex) { logger.getlogger(dbconnection.class.getname()).log(level.severe, null, ex); } } public int insertvalues(string sql){ seek { connectdb(); statement st = con.createstatement(); = st.executeupdate(sql); homecoming i; } grab (sqlexception ex) { logger.getlogger(dbconnection.class.getname()).log(level.severe, null, ex); } homecoming i; } public void main (string []args){ dbconnection db = new dbconnection(); db.connectdb(); }

}

following servlet (submituser) values form

package feedback; 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; public class submituser extends httpservlet { private dbconnection db = new dbconnection(); protected void processrequest(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { response.setcontenttype("text/html;charset=utf-8"); printwriter out = response.getwriter(); string comment = request.getparameter("comment"); string sql = "insert test values('comment' )"; int = db.insertvalues(sql); if (i==0){ out.println("<html>"); out.println("<head>"); out.println("<title>servlet submituser</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>you have missed</h1>"); out.println("</body>"); out.println("</html>"); } else{ out.println("<html>"); out.println("<head>"); out.println("<title>servlet submituser</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>successfully submmited</h1>"); out.println("</body>"); out.println("</html>"); } } } @override protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { processrequest(request, response); } /** * handles http <code>post</code> method. * * @param request servlet request * @param response servlet response * @throws servletexception if servlet-specific error occurs * @throws ioexception if i/o error occurs */ @override protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { processrequest(request, response); } /** * returns short description of servlet. * * @return string containing servlet description */ @override public string getservletinfo() { homecoming "short description"; }// </editor-fold>

}

java jsp tomcat servlets

No comments:

Post a Comment