Getting 404 errors
Dear experts,
I have embedded a login page inside my landing page - home.jsp.
So, at the right-hand column of my page,
I use the below codes:-
<ul class="list-one">
<li><div id="fig2_8">
<h4>Login</h4>
<form action="login" method="POST">
<p style="padding-right:15px">ID: <input type="text" name="userid"/></p>
<br/>
<p>Password:<input type="password" name="password" size="15"/></p>
<br/>
</div>
<p><input type="submit" value="Submit" name="submit" />
<input type="reset" value="Reset" name="reset" /></p>
</form>
</ul>
And my servlet codes:-
import java.io.*;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class login extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String userid = request.getParameter("userid");
String password = request.getParameter("password");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/xxx", "xxx", "xxx");
String query = "SELECT count( * ) FROM admin WHERE userid = ? AND password = ?";
PreparedStatement stmt = conn.prepareStatement(query);
stmt.setString(1, userid);
stmt.setString(2, password);
ResultSet resultSet = stmt.executeQuery();
resultSet.next();
int columnCount = resultSet.getInt(1);
if (columnCount == 1) {
out.println("<html>");
out.println("<head><title>Login Success</title></head>");
out.println("<body>");
out.println("<p>Login Success! Welcome " + userid);
out.println("</body></html>");
out.println("<a href=\"search.jsp\">Click here to search tutors</a>");
//response.sendRedirect("AddMember.jsp");
} else {
out.println("<html>");
out.println("<head><title>No Such User</title></head>");
out.println("<body>");
out.println("<p>Login Failed! " + userid);
out.println("<p>No such user exists, " + userid);
out.println("</body></html>");
out.println("<a href=\"index.jsp\">Click here to login</a>");
out.close();
conn.close();
}} catch (Exception e) {
System.out.println("Error" + e.getMessage());
}
// response.sendRedirect("home.html");
try {
/* TODO output your page here
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Servlet1</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet Servlet1 at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
*/
} finally {
out.close();
}}}
my database is 3 fields :-
userid
password
access
I received a 404 errors and I identified that the servlet doesn't appear in the xml mapping inside my netbean IDE.
However, even when I tried manually add in the xml, it's still not working.
I wonder is it because the login portion can't be embedded inside and I have to create a class for the login page? I'm not sure and I'm hoping you experts will advise me. I have only done something in which the login page is on its own and so may be there's something that I need to do but I don't know what is it....Kindly advise me again. Thank you so much.
View Answers
August 6, 2010 at 12:13 PM
Hi Friend,
We have modified your code, try the following:
1)jsp
<ul class="list-one">
<li><div id="fig2_8">
<h4>Login</h4>
<form action="../login" method="POST">
<p style="padding-right:15px">ID: <input type="text" name="userid"/></p>
<br/>
<p>Password:<input type="password" name="password" size="15"/></p>
<br/>
</div>
<p><input type="submit" value="Submit" name="submit" />
<input type="reset" value="Reset" name="reset" /></p>
</form>
</ul>
2)login.java
import java.io.*;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class login extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String userid = request.getParameter("userid");
String password = request.getParameter("password");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:
mysql://localhost/test", "root", "root");
String query = "SELECT count( * ) FROM user_details WHERE username = ? AND password = ?";
PreparedStatement stmt = conn.prepareStatement(query);
stmt.setString(1, userid);
stmt.setString(2, password);
ResultSet resultSet = stmt.executeQuery();
resultSet.next();
int columnCount = resultSet.getInt(1);
if (columnCount == 1) {
out.println("<html>");
out.println("<head><title>Login Success</title></head>");
out.println("<body>");
out.println("<p>Login Success! Welcome " + userid);
out.println("</body></html>");
out.println("<a href=\"search.jsp\">Click here to search tutors</a>");
//response.sendRedirect("AddMember.jsp");
} else {
out.println("<html>");
out.println("<head><title>No Such User</title></head>");
out.println("<body>");
out.println("<p>Login Failed! " + userid);
out.println("<p>No such user exists, " + userid);
out.println("</body></html>");
out.println("<a href=\"index.jsp\">Click here to login</a>");
out.close();
conn.close();
}} catch (Exception e) {
System.out.println("Error" + e.getMessage());
}
out.close();
}}
Thanks
Related Tutorials/Questions & Answers:
Getting 404 errors - Java BeginnersGetting 404 errors Dear experts,
I have embedded a login page inside my landing page - home.jsp.
So, at the right-hand column of my page,
I...
password
access
I received a
404 errors and I identified that the servlet
getting errorsgetting errors public
class positive {
public static void main(String[] args) {
retainPositiveNumbers(a);
}
private
static int n;
private
static int j;
static
int a[]={-1,2,3,4,-5};
static
int
Advertisements
problem getting servlet:xmlHTTP.status=404 - Ajaxproblem
getting servlet:xmlHTTP.status=
404 hi,
ihave a text field in which i type some words and get related response from db via XMLHTTP request... of the servlet, it gets it and teh xmlHTTP.status =
404 condition becomes false.im using
Still getting the http 404 error - Java BeginnersStill
getting the http
404 error Dear experts,
I refer to the last solution given to me.
A few clarification:-
1. I must stress... is userid?
Anyway, whatever I do, I still receive the http
404 error...saying
errorserrors i am
getting an error saying cannot find symbol class string.how do i rectify
errors that what the
errors in above code
404 error404 error struts application having
404 error while hosting to a online server.it works fine in my local machine but dont work in virtual host.showing
404 error
404 error404 error i have
404 error in my addition programe of servlet how should i solve this.
i'm using netbean on glassfish server
404 error404 error i have
404 error in my addition programe of servlet how should i solve this.
i'm using netbean on glassfish server
404 error404 error hello anybody help me
when i deployed my ear file into jboss->server-> default->deploy folder it doesn't shows any error. but when i run this application by using localhost:8080/webapp ,it shows
404 error
404 status received in xmlhttp.status - Ajax404 status received in xmlhttp.status Hi! I tried out the code I found here using the AJAX login page. However, instead of using PHP for the server... is that I am
getting the status
404, instead of 200. thus, I am unable
http 404 resource not found error http
404 resource not found error Sir,
I have downloaded your RichLRApplication and deployed on tomcat 6 with oracle backend.
Application started in tomcat manager. But when I try to run I am
getting http
404 requested resource
Compiler errors in javaCompiler
errors in java Hi,
I used GenerateRDF java file.
Am
getting errors when i run this code.
I used command prompt only.
getting errors as no package exist.
i followed your instructions properly.
Please help me out
loacation of errorpage in web.xml for 404 errorloacation of errorpage in web.xml for
404 error The webpage cannot be found
HTTP
404
Most likely causes:
â?¢There might be a typing error... to and look for the information you want.
More information
This error (HTTP
404 HTTP Status 404 - HTTP Status
404 - HTTP Status
404 -
type Status report
message
description The requested resource () is not available.
Apache Tomcat/5.5.31
how to rectify the above error
What is the errors?What is the
errors? ) while ( c <= 5 )
{
product *= c;
++c;
if ( gender == 1 )
cout << "Woman" << endl;
else;
cout << "Man" << endl;
Post the whole code
jsp errors - JSP-Servlet.
Now i am
getting less
errors compared to previous. But I am
getting 2
errors...jsp errors Hi I got
errors when running a jsp file
I am giving the file.
this is from rose india.
I set the class path for 3 jar files i.e
htpp 404 error "Servlet as is not available"htpp
404 error "Servlet as is not available" hi iam new to struts. when iam running my struts app after filling the login form iam
getting "Servlet as is not available".
iam unable to find out where the error is.iam pasting my
loginform giving 404 errorloginform giving
404 error Hi,
I am developing a login form code from roseindia.net. i will develop all the formbean class, action class, login.jsp... the submit button the give error is populated.
HTTP Status
404 - /login.doADS
htpp 404 error "Servlet as is not available"htpp
404 error "Servlet as is not available" hi iam new to struts. when iam running my struts app after filling the login form iam
getting "Servlet as is not available".
iam unable to find out where the error is.iam pasting my
HTTP Status 404 - StrutsHTTP Status
404 Hello,
i am making a program of tiles using Struts2. i face error HTTP Status
404
May 4, 2010 11:31:59 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The Apache Tomcat Native library which
Java Program ErrorsJava Program Errors These are the 2
errors which I am
getting when executing the java source code extracted from executable jar file
The project was not built since its build path is incomplete. Cannot find the class file
ModuleNotFoundError: No module named 'errors'ModuleNotFoundError: No module named '
errors' Hi,
My Python... '
errors'
How to remove the ModuleNotFoundError: No module named '
errors'... to install padas library.
You can install
errors python with following command
HTTP Status 404 - JSP-ServletHTTP Status
404 Respected Sir/madam,
I am R.Ragavendran.. I am using J2EE1.4 SDK Application Server.. When I was working with it yesterday,Suddenly i found my server throwing the following Error:
HTTP Status
404 STRUTS2.0 Validation Errors the previous field
errors persist in the page.
For eg:if i am not entering both... message("username is required") is not
getting removed.It still shows both
ubuntu disco Release 404 Not Foundubuntu disco Release
404 Not Found Hi,
I am trying to update my...://in.archive.ubuntu.com/ubuntu disco Release
404 Not Found [IP: 43.255.166.254 80]
Err:5 http://in.archive.ubuntu.com/ubuntu disco-updates Release
404 Not Found [IP
selectoptions errors in java scriptselectoptions
errors in java script hi,
in my web page when I select the color of the image it displays that particular color but when i again opt the select option it displays
errors message. How do I rectify this problem
Servlets errors in same page.Servlets
errors in same page. How do I display
errors list in the same page where a form field exists using servlets...........i.e. without using JSP? Please explain with a simple username password program
The errors tagIn this section, you will learn about the
errors tag of the Spring form tag library
HTTP Status 404 - /Login/userdetail.javaHTTP Status
404 - /Login/userdetail.java I using netbeans to coonect.. why always error.. help pls.. thx
index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<
Getting an error :(Getting an error :( I implemented the same code as above..
But
getting this error in console...
Console
Oct 5, 2012 10:18:14 AM...)
at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:
404 getting variables getting variables how to get variables from servlet program to webservice program
HTTP Status 404 - /user/AddToCart.do - StrutsHTTP Status
404 user AddToCart Hi, I download the JSP source code to run the online shopping cart. Whenever I try to add a Item to cart, it shows me the error page with HTTP Status
404 - /user/AddToCart.do What
Correct errors - Java BeginnersCorrect errors Identify and correct the
errors in the following program:
public java Method
{
public static method1(int n, m)
{
n += m;
xMethod(3. 4);
}
public static int xMethod(int n)
{
if (n > 0) return 1
getting the emplogetting the emplo I have one table "EMPLOYEEMASTER" contains 'emp id', 'employee name'
for eg:
emp id employee name... kumar
i want the sql statement for
getting like
Getting NumberFormatExceptionGetting NumberFormatException Thanks for the reply. Its works well, but whenever I'm using numeric value from 0010 to 0757 it is returning some garbage value. I dont have the idea what is going wrong. Please give me some idea