• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error in the servlet code

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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("jdbc:oracle: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)
{

}
}
}
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic