Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Getting 404 errors
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Karen
Getting 404 errors
1 Answer(s)      4 years and 5 months ago
Posted in : Java Beginners


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.

Advertisement
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 Beginners
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... I received a 404 errors and I identified that the servlet doesn't appear
getting errors
getting 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 - Ajax
problem 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 Beginners
Still 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
i am Getting Some errors in Struts - Struts
i am Getting Some errors in Struts   I am Learning Struts Basics,I am Trying examples do in this Site Examples.i am getting lot of errors.Please Help me
Getting HTTP 404 error in Spring web MVC with Hibernate Integration
Getting HTTP 404 error in Spring web MVC with Hibernate Integration   Hi, i am Getting HTTP 404 error in Spring web MVC with Hibernate Integration after click on submit button. so provide me a better solution.   
defined actions in struts config still getting a HTTP 404 - Struts
defined actions in struts config still getting a HTTP 404  Hi guys, I am getting an Invalid Path requested error. Heres the code snippet from... I get this error HTTP Status 404 - Invalid path /pages/tiles/AddNewCurrency
errors
errors  i am getting an error saying cannot find symbol class string.how do i rectify
errors
that what the errors in above code
404 error
404 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 error
404 error  i have 404 error in my addition programe of servlet how should i solve this. i'm using netbean on glassfish server
404 error
404 error  i have 404 error in my addition programe of servlet how should i solve this. i'm using netbean on glassfish server
404 error
404 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
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
404 status received in xmlhttp.status - Ajax
404 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
loacation of errorpage in web.xml for 404 error
loacation 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
check for errors
check for errors  How can I check for errors
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
Compiler errors in java
Compiler 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
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
loginform giving 404 error
loginform 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.do type
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
compilation errors
() { } } giving errors: 1) WelcomeServlet.java:37: ')' expected
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
HTTP Status 404 - Struts
HTTP 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
types of errors in php
types of errors in php  What are the different types of errors in php
Java Program Errors
Java 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
custom 404 error page php - PHP
custom 404 error page php  What is this error means: custom 404 error page php
HTTP Status 404 - JSP-Servlet
HTTP 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
Advertisements
 

 

 

DMCA.com