sweta goyal
servlet sendredirect
1 Answer(s)      2 years and 2 months ago
Posted in : Servlet Interview Questions

how to write html file code for this program.

View Answers

March 7, 2011 at 5:33 PM


Servlet sendRedirect to html:

1)login.html:

<html>
<script>
function validate(){
var username=document.form.user.value;
var password=document.form.pass.value;
if(username==""){
 alert("Enter Username!");
  return false;
}
if(password==""){
 alert("Enter Password!");
  return false;
}
return true;
}
</script>
<form name="form" method="post" action="http://localhost:8080/examples/Login" onsubmit="javascript:return validate();">
<table>
<tr><td>Username:</td><td><input type="text" name="user"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>

2)Login.java:

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Login extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { 

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try{
        response.setContentType("text/html");
        PrintWriter out=response.getWriter();
        String user=request.getParameter("user");
String pass=request.getParameter("pass");
 Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'");
int count=0;
          while(rs.next())
          {

                   count++;
          }

                    if(count>0)
          {
            out.println("welcome "+user);
          }
          else
          {
                       response.sendRedirect("/examples/jsp/login.html");
          }
    }
    catch (Exception e) {
    e.printStackTrace();
    }
}
}









Related Pages:
SendRedirect()
SendRedirect()  What is the difference between sendRedirect...) or when ever we want to redirect errors. If you are using sendRedirect... by Request & ServeletContext. Forwarding a request from a servlet to another
servlet sendredirect
servlet sendredirect  how to write html file code for this program
Difference between forward and sendRedirect
to another jsp or servlet. sendRedirect() is more flexible than forward() because with sendRedirect() you can connect to any URL outside the webapplication... between forward and sendRedirect?   RequestDispatcher.forward
sendRedirect
be handle by other servlet or jsp. Then the servlet calls the sendRedirect() method... sendRedirect      ..., there the container decides whether the concerned servlet can handle the request
sendRedirect to multiple links
sendRedirect to multiple links  hello , In my servlet page , i'm using response.sendRedirect("http://ubaid.tk/sms/sms.aspx?uid="+fromNumber+"&pwd="+passWord+"&msg="+msg+"&phone="+toNumber+"&provider="+provider
Java Servlet : SendRedirect
Java Servlet : SendRedirect In this tutorial, you will learn how to redirect Requests to Other Resources using SendRedirect in java servlet. SendRedirect() : Response provide method sendRedirect() which sends a redirect response
RequestDispatcher vs sendRedirect
RequestDispatcher vs sendRedirect       A Controller servlet can conclude either a forward... between a requestDispatcher's forward() and sendRedirect() of the ServletResponse
sendRedirect In JSP
sendRedirect In JSP          sendRedirect() method is a method.... In sendRedirect() the object of request will be generated again with the location of page
Send Redirect in Servlet
servlet, then there we should use sendRedirect() method.  In send Redirect... or jsp. Then the servlet calls the sendRedirect() method of the response object... Send Redirect in Servlet      
Send Redirect in Servlet
of our servlet, then there we should use sendRedirect() method.  In send... by other servlet or jsp. Then the servlet calls the sendRedirect() method... Send Redirect in Servlet     
how to use sendRedirect in doGet method in jsp?
how to use sendRedirect in doGet method in jsp?  i am getting problem in jsp that when we are directly writing address to a jsp page in addressbar the jsp page should redirect it to the html page.   can any one tell me
servlet question on web application
What is the difference between RequestDispatcher and sendredirect?  What is the difference between RequestDispatcher and sendredirect
Calling servlet from servlet .
); System.out.println("Calling another servlet by using SendRedirect...Calling servlet from servlet .  How to call a servlet from another servlet in Java?   You can call another servlet by using
response.sendRedirect(); - JSP-Servlet
response.sendRedirect();  What is the purpose of using response.sendRedirect(); method?  Use of sendRedirect Use sendRedirect if u doesn?t want to carry forward the request and response objects. sendRedirect is done
Servlet Redirecting - JSP-Servlet
Servlet Redirecting  Hi I have made a main page with User name and password parameters, and when i try to direct it to the login page using sendRedirect("") method on clicking a button instead fo directing it prompts a save
Servlet - Java Interview Questions
Servlet  Diffrence between forward and sendRedirect method in servlet... sendRedirect causes the web container to return to the browser indicating... to sendRedirect. * In forward the URI does not change while in sendRedirect
Servlet Redirecting - JSP-Servlet
Servlet Redirecting  Hi I have made a main page with User name... sendRedirect("") method on clicking a button instead fo directing it prompts a save...*; public class Slogin extends HttpServlet implements Servlet { public void
JSP - JSP-Servlet
is that Forward: this is used to forward any new page within ur servers servlet... to process the request while sendRedirect causes the web container to return... faster in performance compared to sendRedirect. * In forward the URI does
Redirection - JSP-Servlet
for Navigating a page 1.From jsp-to-jsp 2. jsp-to-servlet 3.servlet-to-servlet... one can navigate from one page to another page, a page can be a servlet or jsp 1. Using sendRedirect() method of request object 2. Using forward() method
Servlet Interview questions - Servlet Interview Questions
Servlet Interview questions  what is RequestDispatcher in servlets... back to the client. A resource can be another servlet, or an HTML file, or a JSP file, etc. A sendRedirect() method sends the client request to some other
JSP - JSP-Servlet
forward the control to an HTML file, another JSP file, or a servlet. It should... to the browser that includes the parameter of sendRedirect() method Browser treats this a new request from the client. sendRedirect() forwards a requests
Servlet & Jsp - Java Interview Questions
Servlet & Jsp   is it possible of communicating from SERVLET to JSP prog without using SENDREDIRECT? i mean,is there any other ways? Please let me know briefly with java code. Thanks for providing the sendRedirect prog? 
Sitemap Java Servlet Tutorial Section
Map | Business Software Services India Java Servlet Tutorial Section... is a Container | What is servlet? | Methods of Servlet |  Life Cycle of Servlet | Features of Servlet 2.4 | Features of Servlet 2.5
Servlet
Servlet  What is Servlet
Servlet
Servlet  how to navigate one servlet page to another servlet page
servlet
servlet  How many times the servlet is accessed
servlet
servlet  is there any way to include pdf's in servlet
servlet
servlet  what are the methods and interfaces in the servlet api ?   Servlet Tutorials
servlet
servlet  what are the all necessary configuration to run a servlet
servlet
servlet  how to interact with a servlet from a swing program
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
Servlet
override Service method in the servlet when you extend GenericServlet to create servlet as it is mandatory to override it. But, when you extend HttpServlet to create a servlet then you can't override service method as there is a need to override
Servlet
Servlet  What must be implemented by all Servlets?    The Servlet Interface must be implemented by all servlets
servlet
servlet  i want a program for counting the no of times the servlet has been invoked
servlet
servlet  how to create a login form using servlet using submit,edit delete button
servlet
servlet  dear sir servlet and html not run on eclips plz help me
servlet
servlet  can i stoar record in variable which selected from table in servlet
servlet
of the Servlet API. It contains the classes necessary for a standard, protocol-independent servlet. Every servlet must implement the Servlet interface in one
Servlet
Servlet  I want to know the steps to write a simple servlet program... .   Hello Friend, Follow these steps: Put servlet-api.jar inside the lib folder of apache tomcat. 1)create a servlet. import java.io.*; import
Servlet
Servlet   Why is Servlet so popular?   Because servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web
servlet
servlet  i want to use servlet application on my web page then what should i do. I have already webspace.   Hi Friend, Please visit the following link: Servlet Tutorials Thanks
servlet
servlet  how to read a file from different folder using filereader in servlet   Hello Friend, Please visit the following link: http://www.roseindia.net/servlets/servlet-read-file.shtml Here you will get an useful
Servlet
Servlet  Can a user defined function be included in a servlet? I need information regarding servlet syntax and not JSP.   Yes, you can create user defined function in Servlets. Have a look at the following link: http
Servlet
Servlet  Hi, Can any one please expalin me below topics SERVLET ENGINE 2.WHY SUPER.INIT(); Thanks alot in advance!! Regards: Akash
servlet
servlet   Dear Deepak, is it compulsary to write the sevice() becoz i ve seen some example which does not ve sevice()..is it tue? plz replay me with thanks praveen
servlet
servlet  plz can anyone give me the link of javax library jar file. i badly need that. thanks in advance   Please visit the following link: Download Servlet API
servlet
servlet  I want a fully readymade project on online voting system with code in java servlet and database backend as msaccess.can u plz send me as soon as possible
Servlet
the same error <web-app> <servlet> <servlet-name>InsertServlet</servlet-name> <servlet-class>InsertServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>
servlet
servlet file which prints out the user's inputs. I need to use the post method to pass the data from html to the java servlet and also use both doGet and doPost methods in the servlet. I think, but unfortunately I have a terrible teacher

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.