File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes IDEs, Version Control and other tools and the fly likes error in the servlet code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "error in the servlet code" Watch "error in the servlet code" New topic
Author

error in the servlet code

avinashguru prasad
Greenhorn

Joined: Nov 23, 2012
Posts: 14
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
Marshal

Joined: Mar 22, 2005
Posts: 42929
    
  68
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

Joined: Dec 08, 2012
Posts: 4
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.


Obessed with computers, mobile devices, linux, coding, scuba diving, boxing and coffee...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42929
    
  68
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error in the servlet code