File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes HTTP STATUS 404: requested resource is not available. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP STATUS 404: requested resource is not available." Watch "HTTP STATUS 404: requested resource is not available." New topic
Author

HTTP STATUS 404: requested resource is not available.

Trupti brane
Greenhorn

Joined: Aug 16, 2011
Posts: 20

HTML CODE:

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="http://localhost:8084/WebApplication3/NewServlet2" method="get">
<table>

<tr>
<th align="center"> SIMPLE FORM </th>
</tr>
<tr>
<td> NAME:</td><td><input type="text" name="name" maxlength="25"></td>
</tr>
<tr>
<td> AGE:</td><td><input type="text" name="age" maxlength="2"></td>
</tr>
<tr>
<td></td>
<td> <input type="Submit" name="SUBMIT" value="Submit" ></td>
</tr>

</table>
</form>


</body>
</html>



SERVLET CODE
import java.io.*;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.net.*;


public class NewServlet2 extends HttpServlet{

Connection theConnection;
private ServletConfig config;

public void init(ServletConfig config)
throws ServletException{
this.config=config;

}

public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

HttpSession session = request.getSession(true);
response.setContentType("text/html");
PrintWriter out = response.getWriter();


out.println("<HTML><HEAD><TITLE>Information</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<P align=center><BIG><BIG>List of Students.</BIG></BIG></FONT></P>");
out.println("<P align=center>");
out.println("<TABLE align=center border=1 cellPadding=1 cellSpacing=1 width=\"75%\">");

out.println("<TR>");
out.println("<TD>Name</TD>");
out.println("<TD>Age</TD>");
out.println("<TR>");

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//Loading Sun's JDBC ODBC Driver
theConnection = DriverManager.getConnection("jdbcdbc:db"); //Connect to db Data source
Statement stmt=theConnection.createStatement();
String Name= request.getParameter("name");
String Age= request.getParameter("age");
String query="insert into stud values('"+Name+"','"+Age+"')";

int c=stmt.executeUpdate(query);

if(c>0)
{
ResultSet theResult=stmt.executeQuery("select * from stud"); //Select all records from emaillists table.
while(theResult.next()) //Fetch all the records and print in table
{
out.println();

out.println("<TR>");
out.println("<TD>" + theResult.getString(1) + "</TD>");
out.println("<TD>" + theResult.getString(2) + "</TD>");
out.println("</TR>");

}

theResult.close();//Close the result set
stmt.close();//Close statement
theConnection.close(); //Close database Connection
}
}catch(Exception e){
out.println(e.getMessage());//Print trapped error.
}


out.println("</TABLE></P>");
out.println("<P> </P></FONT></BODY></HTML>");


}
public void destroy(){

}

}


Every time i write the code i get the HTTP STATUS 404 requested resource is not available.
please do give some suggestions.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Follow the usual debugging steps:
  • Be sure that your servlet is in a package other than the default.
  • Make sure that your servlet is properly mapped to a URL in the deployment descriptor.
  • Make sure that you use the mapped URL properly when addressing the servlet. Don't forget to include the context path.


  • [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
     
     
    subject: HTTP STATUS 404: requested resource is not available.