0% found this document useful (0 votes)
13 views15 pages

MVC Login Implementation in Java

Uploaded by

gu8677014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views15 pages

MVC Login Implementation in Java

Uploaded by

gu8677014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

[1]To demonstrate the web development by using MVC design pattern.

[Link](View)

<form action="ControllerServlet" method="post">

Name:<input type="text" name="name"><br>

Password:<input type="password" name="password"><br>

<input type="submit" value="login">

</form>

[Link](view)

<%@page import="[Link]"%>

<p>You are successfully logged in!</p>

<% LoginBean bean=(LoginBean)[Link]("bean");

[Link]("Welcome, "+[Link]());

%>

[Link](View)

<p>Sorry! username or password error</p>

<%@ include file="[Link]" %>


[Link](Model)

package [Link];

import [Link].*;

public class LoginBean {

private String name,password;

public String getName() {

return name;

public void setName(String name) {

[Link] = name;

public String getPassword() {

return password;

public void setPassword(String password) {


[Link] = password;

public boolean validate(){

if([Link]("admin")){

return true;

else{

return false;

}}}

[Link](Controller)

[Link]("text/html");

PrintWriter out=[Link]();

String name=[Link]("name");

String password=[Link]("password");

LoginBean bean=new LoginBean();

[Link](name);
[Link](password);

[Link]("bean",bean);

boolean status=[Link]();

if(status){

RequestDispatcher rd=[Link]("[Link]");

[Link](request,response);

else{

RequestDispatcher rd=[Link]("[Link]");

[Link](request,response);

[2]To develop a Java console application that demonstrates the connection with MySQL database
and perform various operations on it.

import [Link].*;

import [Link].*;

public class Temp {


public static void main(String[] args) {

// TODO Auto-generated method stub

try{

[Link]("[Link]");

Connection
con=[Link]("jdbc:mysql://localhost:3306/employee?characterEncoding=lati
n1","root","root");

Statement stmt=[Link]();

int ans=1;

do {

[Link]("1. Insert a record ");

[Link]("2. Delete a record ");

[Link]("3. Modify/Edit a record ");

[Link]("4. Display list of records ");

Scanner sc = new Scanner([Link]);

[Link]("Enter your choice:");


int ch = [Link]();

String ename;

int eno,age;

String query="";

switch(ch) {

case 1:

[Link]("Enter employee number:");

eno = [Link]();

[Link]("Enter employee name:");

ename = [Link]();

[Link]("Enter employee age:");

age = [Link]();

query = "INSERT INTO emp " + "VALUES (" + eno+ ",'" + ename+"',"+ age+")";

[Link](query);
break;

case 2:

[Link]("Enter employee number:");

eno = [Link]();

query = "delete from emp where eno='"+eno+"'";

[Link](query);

[Link]("Record is deleted from the table successfully..................");

break;

case 3:

PreparedStatement ps = null;

query = "update emp set name=? where eno=? ";

ps = [Link](query);

[Link]("Enter employee number:");

eno = [Link]();

[Link]("Enter employee name:");

ename = [Link]();
[Link](1, ename);

[Link](2, eno);

[Link]();

[Link]("Record is updated successfully......");

break;

case 4:

ResultSet rs=[Link]("select * from emp");

while([Link]())

[Link]([Link](1)+" "+[Link](2)+" "+[Link](3));

[Link]("Enter another(1/0)");

ans = [Link]();

}while(ans==1);

[Link]();
}catch(Exception e){ [Link](e);}

[3] To implement the collection framework by develop a java console application.

import [Link].*;

import [Link].*;

class Student {

int rollno;

String name;

float fees;

String branch;

int year;

int sem;

int age;

static String clg;


public Student(int rollno,String name,float fees,String branch,int year,int sem,int age) {

[Link] = rollno;

[Link] = name;

[Link] = fees;

[Link] = branch;

[Link] = year;

[Link] = sem;

[Link] = age;

clg="PU";

public String toString() {

return rollno + " "+ name + " " + fees + " " + branch + " " + year + sem + " " + age + " " + clg +
"\n";

}
}

class AgeComparator implements Comparator {

public int compare(Object o1, Object o2) {

Student s1=(Student)o1;

Student s2=(Student)o2;

if([Link]==[Link])

return 0;

else if([Link]>[Link])

return 1;

else

return -1;

class NameComparator implements Comparator{

public int compare(Object o1, Object o2) {

Student s1=(Student)o1;

Student s2=(Student)o2;
return [Link]([Link]);

class FeesComparator implements Comparator {

public int compare(Object o1,Object o2) {

Student s1=(Student)o1;

Student s2=(Student)o2;

if([Link]==[Link])

return 0;

else if([Link]>[Link])

return 1;

else

return -1;

public class Temp1 {


public static void main(String[] args) {

ArrayList sl=new ArrayList();

[Link](new Student(1,"Shruthi",10000.00f,"cse",1,1,18));

[Link](new Student(2,"Venky",15000.00f,"ise",1,2,20));

[Link](new Student(3,"Bella",17000.00f,"ece",1,1,19));

[Link](new Student(3,"Alina",12000.00f,"eee",1,1,19));

[Link](new Student(3,"Riya” 11000.00f,"mech",1,1,21));

[Link]("Sorting by Name");

[Link]("_______________");

[Link](sl,new NameComparator());

Iterator itr=[Link]();

while([Link]()){

Student st=(Student)[Link]();

[Link](st. );

}
[Link]("Sorting by age");

[Link]("______________");

[Link](sl,new AgeComparator());

Iterator itr2=[Link]();

while([Link]()) {

Student st=(Student)[Link]();

[Link](st );

[Link]("Sorting by fees");

[Link]("______________");

[Link](sl,new FeesComparator());

Iterator itr1=[Link]();

while([Link]()){

Student st=(Student)[Link]();

[Link](st);

}
}

You might also like