• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error in the servlet code

 
avinashguru prasad
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after runing the following code on netbeans ide 7.0 beta i got following error :"C:\Users\avinash\Documents\NetBeansProjects\CYBERSPACE\nbproject\build-impl.xml:708
The module has not been deployed".




import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class sample1 extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
HttpSession session=req.getSession(true);
try
{
Class.forName("oracle.jdbc.OracleDriver");
Connection con=DriverManager.getConnection("jdbcracle:thin:@localhost:1521:XE","system","avinash");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from customer");

PrintWriter pw=res.getWriter();
res.setContentType("text/html");
String uname=null;
String pwd=null;
String c_id=null;
boolean flag = false;
String s1=req.getParameter("cust_id");
String s2=req.getParameter("username");
String s3=req.getParameter("password");
while(rs.next())
{
c_id=rs.getString(1);
uname=rs.getString(2);
pwd=rs.getString(3);
if(s1.equals(c_id) && s2.equals(uname) && s3.equals(pwd))
{
flag=true;

}
}

if(flag)

{
session.setAttribute("cust_id", s1);
res.sendRedirect("http://localhost:8084/CYBERSPACE/Cust_Home.jsp");

}
else
{
pw.println("Invalid");
pw.println("<a href='http://localhost:8084/CYBERSPACE/c_signin.jsp'> ok </a>");

}
}
catch(Exception e)
{

}
}
}
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not a NetBeans user, so I don't know how it deploys web apps, but why are you using the beta of an already obsolete version of it? Start by installing the current release version of NetBeans.

Also, you should never do this:

catch(Exception e)
{
}

How will you know if there are any problems with the code? At least log the exception to somewhere where you will see it. Even a simple "System.out.println(e.getMessage())" is much better than simply suppressing the exception.
 
Gene Song
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some things you could try:

1. First of all, DB operation code should belong to a model class, not in a servlet.

2. Make sure you have a correct driver jar file loaded in the library.

3. Make sure you are getting connected to the database by separating your codes something like this...


4. Restart the server. Sometimes, if the same named web app cannot be undeployed properly, it fails to deploy.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple further points on the code: You should load the DB driver only once, not for each access - move that part into the servlet's init method.

And get in the habit of closing DB resources when you're done with them - ResultSet, Statement and particularly Connection have close() methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic