This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hai Friends, I have been working on a login servlet program.My code looks like: import java.io.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*;
String title = "Welcome to MailServer"; out.println("<title>" + title + "</title>"); out.println("</head>"); out.println("<body>"); try { Class.forName("com.mysql.jdbc.Driver").newInstance();
out.println("Class done<br>");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "test", ""); out.println("Connection done<br>");
Statement st = con.createStatement(); st.executeUpdate("insert into t_holiday(yr,country) values('"+request.getParameter("yr")+"','"+request.getParameter("country")+"')"); st.close(); con.close(); } catch(Exception e) { out.println("Exception Has Been Caught <br>" + e); } out.println("</body>"); out.println("</html>"); } }
I got everything correct but when i want to see the contents of my database table after updation,its displaying null values.Iam using Mysql as my backend.I have done servlet mapping in my web.xml file.Do I need to do any other corrections?My web.xml file looks as: <?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
</servlet> <servlet-mapping> <servlet-name>Simple</servlet-name> <url-pattern>/Simple</url-pattern> </servlet-mapping> </web-app> I need help fromm you friends. Thank You Ankita
Init parameters and request parameters are different. Don't get them confused. You set init parameters in the servlet configuration (web.xml). Request parameters come in via HTTP (e.g. GET or POST).
In Praful's example you would need to use something like getServletConfig().getInitParameter(param).
Ankita, one other suggestion. Move the JDBC code out of the Servlet and into a plain old Java object for reuse. Servlets should just have code that handles the request and returns a reply. All other work should be handed off to plain old Java objects, and return the values you need to package it up into the Response.