JSP AND SERVLET

Ads
 

JSP AND SERVLET

I want to create a login form with user name and password field,if the user is new then s/he can click on the new user hyperlink and new page will be display,and data will be updated to the database successfully,if the user is already registered then the new page will be opened with his or her name. They can also edit their details by using edit button,and there will be a back button.through which we can go to the home page. Plz help me,im new in this field....................

View Answers

February 6, 2012 at 1:31 PM

1)login.jsp:

<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="check.jsp" 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="Login"></td></tr>
<tr><td></td><td><a href="register.jsp">New User<a></td></tr>

</table>
</form>
</html>

2)check.jsp:

<%@page import="java.sql.*"%>

<%
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("login.jsp");
          }
%>

3)register.jsp:

<html>

<form name="form" method="post" action="insertdata.jsp">
<table>
<tr><td>Enter First Name</td><td><input type="text" name="fname"></td></tr>
<tr><td>Enter Last Name</td><td><input type="text" name="lname"></td></tr>
<tr><td>Enter Username</td><td><input type="text" name="uname"></td></tr>
<tr><td>Enter Pasword</td><td><input type="password" name="pass"></td></tr>
<tr><td>Enter Address</td><td><input type="text" name="address"></td></tr>
<tr><td>Enter City</td><td><input type="text" name="city"></td></tr>
<tr><td></td><td><input type="submit" value="Add" name="button"></td></tr>
</table>
</form>
</html>

February 6, 2012 at 1:32 PM

continue....

4)insertdata.jsp:

<%@page import="java.sql.*,java.util.*"%>
<table>
<%
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String uname=request.getParameter("uname");
String pass=request.getParameter("pass");
String address=request.getParameter("address");
String city=request.getParameter("city");
System.out.println(fname+lname+uname+pass+address+city);
        try{
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
        Statement st=con.createStatement();
        int i=st.executeUpdate("insert into login(firstname,lastname,username,password,address,city) values('"+fname+"','"+lname+"','"+uname+"','"+pass+"','"+address+"','"+city+"')");

        out.println("Data is successfully inserted into database.");

                    con.close();

        }
        catch(Exception e){
        System.out.println(e);
        }
        %>
        </table>

For more information, visit the following link:

http://www.roseindia.net/servlets/web-application.shtml

Ads









Related Tutorials/Questions & Answers:
servlet and jsp
servlet and jsp  how to connect an jsp and an servlet without connecting to database
Servlet - JSP-Servlet
Servlet and Java Code  Example and source code in Servlet and JSP
Advertisements
Servlet - JSP - JSP-Servlet
Servlet - JSP  i used arraylist in servlet as shown ArrayList total = new ArrayList (); ... total.add(k[i]); session.setAttribute("efg",total); when I code this like in my jsp <%ArrayList<Integer> data= new
jsp servlet
jsp servlet  i dont know how to write a code to Create a JSP with one text field to enter the URL and a submit button.On clicking the submit button, send the request to a servlet .Once the servlet receives the request, it need
jsp servlet
jsp servlet  i dont know how to write a code to Create a JSP with one text field to enter the URL and a submit button.On clicking the submit button, send the request to a servlet .Once the servlet receives the request, it need
JSP-Servlet
JSP-Servlet  Hi have created a JSP page and I need to print it when the user clicks on the print button. I have put a print button on the JSP page. Can somebody plz help me out with the Servlet page coding
jsp and servlet
the data and delete the data,using jsp and servlet...jsp and servlet  I want to create a login form,which have many fields,and have a connectivity with thwe oracle database,and login form will have
jsp and servlet
jsp and servlet  hello friends just want to create a jsp page... login from login page and if we submit it shud be validated in a servlet using... links: http://www.roseindia.net/jsp/loginbean.shtml http://www.roseindia.net
jsp servlet
code to Create a JSP with one text field to enter the URL and a submit button  i dont know how to write a code to Create a JSP with one text field... the request to a servlet .Once the servlet receives the request, it need to create
jsp servlet
how to write a code to Create a JSP with one text field to enter the URL  i dont know how to write a code to Create a JSP with one text field... to a servlet .Once the servlet receives the request, it need to create a thread
servlet and jsp
servlet and jsp  how can i get a form question from a database... with servlets and jspīs   Have a look at the following links: http://www.roseindia.net/jsp/paging.shtml http://www.roseindia.net/jsp/navigation
How to call servlet in JSP?
How to call servlet in JSP?  How to call servlet in JSP
Java Servlet - JSP-Servlet
Java Servlet   Hello Sir Could you help me in understanding directory Structure for servlet page in eclipse (IDE). I save my Sevlet in WEB-INF but it is not displaying, it is displaying code of servlet. Process used
jsp and servlet
jsp and servlet  If i want to get dynamic value in html textbox or in jsp,then how can I get the value,how the value will be transfered from servlet... javax.servlet.*; import javax.servlet.http.*; public class Servlet extends
calling servlet from jsp
calling servlet from jsp  how to call a servlet from jsp
SERVLET AND JSP
SERVLET AND JSP  If i want tio create a login form using SUBMIT,ADD...;For more information visit the following links: http://www.roseindia.net/jsp/user...://www.roseindia.net/answers/viewqa/JSP-Servlet/16413-using-insert-and-delete-in-a-single
SERVLET AND JSP
SERVLET AND JSP  If i want tio create a login form using SUBMIT,ADD...;For more information visit the following links: http://www.roseindia.net/jsp/user...://www.roseindia.net/answers/viewqa/JSP-Servlet/16413-using-insert-and-delete-in-a-single
EL in jsp - JSP-Servlet
. The default mode for JSP pages delivered using a Servlet 2.3 or earlier descriptor... for JSP pages delivered with a Servlet 2.4 descriptor is to evaluate EL...EL in jsp  hai, I tried to test EL operators in my jsp i
jsp program - JSP-Servlet
jsp program  1.write a servlet program that finds out the given... an application in jsp to redirect the request to any other page.  Hi Friend...,please go through the following link: http://www.roseindia.net/jsp/jsp
java - JSP-Servlet
java  why is required to write both jsp and servlet in a application of java
Servlets vs JSP - JSP-Servlet
and servlet act as a controller. 2)JSP pages contain a mixture of HTML, Java scripts, JSP elements, and JSP directives while servlet is totally uses java code. 3... and servlet is used for bussiness logic 5)Servlets are faster than jsp. 6
coding in jsp & servlet
coding in jsp & servlet  plz... provide me coding of "online examination system" in jsp & servlet
Example questions of JSP & Servlet
Example questions of JSP & Servlet  Give me some JSP & Servlet Question and their answers
java - JSP-Servlet
java  what is the difference between jsp and servlet?   Hi firend, Main difference between Jsp and Servlet Jsp is better for view web pages, while servlet is good for request processing. Jsp has also all
jsp servlet hosting
jsp servlet hosting  Hi, What is jsp servlet hosting? Thanks   In case of jsp servlet hosting, hosting companies are providing hosting environment where client can host Java based web application on the server
login authentication in jsp and servlet
to make login authentication in jsp and servlet? Thanks   Hi, I to make login authentication in jsp and servlet you have to write code for database... it with complete code: Login Authentication using Bean and Servlet In JSP JSP
Calculator - JSP-Servlet
Calculator  Dear Deepak Sir, Calculator program is avilable in Jsp/Servlet plz send me. Thanks & Regards, VijayaBabu.M  Hi vijay calculator program in jsp function checkValue(){ var msg
Project - JSP-Servlet
Project  Can you send me the whole project on jsp or servlet so that i can refer it to create my own : the topic is Advertisement Management System Atleast tell me how many modules does it include
java servlets - JSP-Servlet
java servlets  how to get the parameter value of input type file using java servlets  Hi, You can use request.getParameter(). In Jsp, --- --- IN servlet, String fileName=request.getParameter('fl'); If you
jsp/servlet login program
jsp/servlet login program  <%@ page language="Java" import...;/TITLE></HEAD> <BODY> <jsp:useBean id="db" scope="request" class="logbean.LoginBean" > <jsp:setProperty name="db" property="userName" value
Populating child dropdownlists in JSP/Servlet
Populating child dropdownlists in JSP/Servlet  Populating child dropdownlists in JSP/Servlet

Ads