Home Answers Viewqa Java-Beginners MVC architecture example

 
 


shxrainz
MVC architecture example
2 Answer(s)      4 years and 9 months ago
Posted in : Java Beginners

View Answers

September 4, 2008 at 5:13 PM


HI,

Follow the procedure
1.Create a jsp page name like login.jsp(remember in login.jsp in action you will put the servlet name like action="login.java")
2.Then create a servlet page name like login.java
3.Then create another java class Login.java(It the same name of the sevlet)where get and set mathod will be used.

4.Then create another java class where you will put your database connectivity logic.


Go through the code and create the files USING netbeans ide or eclipse then
enjoy :)))))))))))

here is the code for jsp page like login.jsp(omit the css thingd just pick up the html code and make page by yourself)






<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">;
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="fr"><head><title>Secure Networks Technologies - Web Server</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<link rel="stylesheet" href="cryptonet_files/config.css" type="text/css">
<style type="text/css">
.style1 {
color: red;
}
</style><script charset="utf-8" id="injection_graph_func" src="cryptonet_files/injection_graph_func.js"></script></head><body>

<div id="container">

<div id="banner"> <img src="cryptonet_files/bluetooth.jpg" alt="" border="1" height="100" width="798">
<img src="cryptonet_files/Safe%2520Server.jpg" alt="" border="1" height="100" width="798">
</div>

<div id="outer">
<div id="inner">
<div id="left" style="">

<br>
<strong>
</strong><pre><a href="index.jsp"><img src="images/home.png" border="0" width="32" height="32" > &nbsp;&nbsp;</a><span class="style1"><a href="index.jsp"> <font color = red> Home </font> </a></span>
</pre>

<p>
<br>
<br>

</p>
</div>
<div id="content" style="">

<h1> Login</h1>

<p class="MsoNormal">
<span lang="EN-US">
<br>
</span>
</p><p><span lang="EN-US"></span></p>
<span lang="EN-US"><table border="0" cellpadding="0" cellspacing="0">

<!-- CryptoNet Section ----------------------------------------------------- -->
<tbody><tr> <td colspan="2"> <table width="476" border="0">
<tr>
<td width="186">User Name </td>
<td width="274">
<form name="form2" id="form2" method="post" action="login.java">
<input type="text" name="textfield" />
</form></td>
</tr>

<tr>
<td>Password</td>
<td><input type="text" name="textfield2" /></td>
</tr>



<tr>
<td>&nbsp;</td>
<td>&nbsp;<span lang="EN-US"><span lang="EN-US"><span lang="EN-US"><span lang="EN-US">
<input type="submit" name="Submit" value="Login" />
</span></span></span></span></td>
</tr>
</table> <strong> </strong></td></tr>
<!-- blank line -->
<!-- blank line -->

<!-- BotNet Section ----------------------------------------------------- -->
<!-- blank line -->
<!-- blank line -->

<!-- WirelessNet Section ----------------------------------------------------- -->
<!-- blank line -->

<tr> <td width="60"> </td>
<td align="west" valign="top" width="500">
<form name="form1" id="form1" method="post" action="">
<span lang="EN-US"><span lang="EN-US"><span lang="EN-US"><span lang="EN-US">
</span></span></span></span> <span lang="EN-US"><span lang="EN-US">
</span></span>
</form></td>
</tr>
</tbody></table>
<span lang="EN-US"></span><br>
<br>
</span>
<p>&nbsp; </p>

</div>
<!-- end content -->

</div>
<!-- end inner -->
</div><!-- end outer -->

<div id="footer"> Last updated on May 02, 2008</div>

</div><!-- end container -->

</body>
</html>



login.java servlet code is given below:

package com.servlet;

import java.io.IOException;
import com.model.idms.Login;
import com.model.idms.actions.IDMSDelegate;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
*
* @author hasan
*/
public class login extends HttpServlet {

public login(){
super();
}
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();

String username=request.getParameter("username");
String password=request.getParameter("password");

//Create the instance of the Login class
Login login=new Login();
login.setusername(username);
login.setpassword(password);

//create the instance of the IDMS Delegate

IDMSDelegate idmsdelegate=new IDMSDelegate();
idmsdelegate.addlogin(login);





HttpSession session=request.getSession(true);
session.setAttribute("loginobject",login);


getServletConfig().getServletContext().getRequestDispatcher("/submit_app.jsp").forward(request,response);

}






protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
*/


}



This is the code of Login.java where the set and get method is given below:


package com.model.idms;

/**
*
* @author hasan
*/
public class Login {

private String firstname;
private String lastname;
private String email;
private String username;
private String password;
private String contract_type;
//private String identification_type;
private String creditcard;
private String co;
private String zipcode;
private String identification;
private String number;
private String contract;
private String street;
private String country;
private String language;
private String amount;
private String interval;
private String address;
private String city;
private String cellphone;
private String homephone;
private String currency;
private String payment;
private String frequency;

public void sethomephone(String homephone){

this.homephone=homephone;
}
public String gethomephone(){

return homephone;
}

public void setfrequency(String frequency){

this.frequency=frequency;

}

public String getfrequency(){

return frequency;
}

public void setcountry(String country){

this.country=country;

}

public String getcountry(){

return country;
}

public void setlanguage(String language){

this.language=language;
}

public String getlanguage(){

return language;
}

public void setinterval(String interval){

this.interval=interval;
}
public String getinterval(){

return interval;

}

public void setcity(String city){

this.city=city;
}

public String getcity(){

return city;

}

public void setamount(String amount){

this.amount=amount;
}
public String getamount(){

return amount;
}
public void setpayment(String payment){

this.payment=payment;
}
public String getpayment(){

return payment;
}
public void setaddress(String address){

this.address=address;
}
public String getaddress(){

return address;
}
public void setcurrency(String currency){

this.currency=currency;
}
public String getcurrency(){

return currency;
}
public void setcellphone(String cellphone){

this.cellphone=cellphone;

}
public String getcellphone(){

return cellphone;
}







public void setstreet(String street){

this.street=street;
}
public String getstreet(){

return street;
}


public void setco(String co){

this.co=co;
}

public String getco(){

return co;

}

public void setzipcode(String zipcode){

this.zipcode=zipcode;
}

public String getzipcode(){

return zipcode;
}

public void setidentification(String identification){

this.identification=identification;
}
public String getidentification(){

return identification;
}

public void setnumber(String number){

this.number=number;
}
public String getnumber(){

return number;
}

public void setcontract(String contract){

this.contract=contract;
}
public String getcontract(){

return contract;
}
public void setcreditcard(String creditcard){

this.creditcard=creditcard;

}
public String getcreditcard(){

return creditcard;
}
public void setcontract_type(String contract_type){
this.contract_type=contract_type;
}
/*public void setidentification_type(String identification_type){

this.getidentification_type=identification_type;
}
*/

public void setfirstname(String firstname){
this.firstname=firstname;

}

public String getfirstname(){
return firstname;
}

public void setlastname(String lastname){
this.lastname=lastname;
}

public String getlastname(){
return lastname;

}

public void setemail(String email){
this.email=email;
}
public String getemail(){
return email;
}


public void setusername(String username) {
this.username=username;
}


public String getusername(){

return username;
}

public void setpassword(String password){
this.password=password;
}

public String getpassword(){

return password;
}

}



here is the IDMSDelegate.java





package com.model.idms.actions;

import com.model.idms.Login;
import com.utility.DBHandlerIdms;
import java.sql.ResultSet;


/**
*
* @author hasan
*/
public class IDMSDelegate {

private DBHandlerIdms db = new DBHandlerIdms();





private ResultSet rs = null;

public boolean addlogin(Login login){
try{

db.makeconnection();
//String query= "insert into login(username,password) values('"+Login.getusername()+"','"+Login.getpassword()+"')";





String query = "insert into login (username,password) values ('"+login.getusername()+"','"+login.getpassword()+"' )";
int a=db.executeUpdate(query);

if(a>0){
db.releaseConnection();

return true;

}
else{
db.releaseConnection();
return false;
}


}catch(Exception ex){
ex.printStackTrace();
return false;
}



}

}




And here is the IDMDHandler.java



package com.utility;
import java.sql.*;


/**
*
* @author hasan
*/
public class DBHandlerIdms {

public Connection connection;
public Statement stmt;
public ResultSet rs;

public String user="root";
public String pass="admin";

public String url="jdbc:mysql://localhost:3306/idms";;
public String driver="com.mysql.jdbc.Driver";



//public String url="jdbc:mysql://localhost:3306/idms";;
//public String driver="com.mysql.jdbc.Driver";

public DBHandlerIdms(){
}

public Connection makeconnection()throws Exception{
Class.forName(driver);
connection=DriverManager.getConnection(url,user,pass);
return connection;
}



public void releaseConnection()throws Exception{
connection.close();

}
public ResultSet executeQuery(String query)throws Exception{

rs=null;
stmt=connection.createStatement();
rs=stmt.executeQuery(query);
return rs;
}
public int executeUpdate(String query)throws Exception{
int rowaffected=0;
stmt=connection.createStatement();
rowaffected=stmt.executeUpdate(query);
return rowaffected;
}

}















September 4, 2008 at 9:52 PM


Hi friend,



Read for more information.

http://www.roseindia.net/jsp/loginbean.shtml


Thanks.









Related Pages:
mvc architecture - Java Beginners
mvc architecture  i am asking you give me an example for the object oriented programming using MVC architecture then my problem is railway tickect... to that arraylist. for this one i have to do code in MVC architecture
mvc architecture - Java Beginners
mvc architecture  can u please provide a example program with code using mvc architecture mine problem is adding routes for the railwaystation... on the MVC architecture please send me the link for knowing the implementation code
MVC architecture example - Java Beginners
MVC architecture example  hi.. I would like to ask the example on Login authentication using MVC model. I really don't understand how it work. Can u give me some example of login authentication using JSP+Servlet+Javabeans
MVC - Struts
MVC  CAN ANYONE GIVE ME A REAL TIME IMPLEMENTATION OF M-V-C ARCHITECTURE WITH A SMALL EXAMPLE......  Hi friend, Read for more information. http://www.roseindia.net/struts/mvc-architecture.shtml Thanks
mvc
mvc  I want MVC example using jsp,servlets,pojoclass,jdbc(with mysql)..operation of insert,search,delete,update. I want above web application only in "Model view controller" format. last time i asked the same question, but i
MVC Architecture
MVC Architecture       The main aim of the MVC architecture  is to separate the business... are the reasons why we should use the MVC design pattern. They are resuable : When
MVC Architecture In Java
MVC Architecture In Java In this section we will discuss about the MVC architecture. This section will describe you all the aspects of MVC architecture..., what is MVC architecture, what is model, what is view, what is controller
MVC Example
MVC Example  I WANT MVC EXAMPLE PROGRAM using Jsp Servlets and Jdbc with mysql of Insert,update,delete,search. please give the answer in MVC rule
About MVC 2 architecture and jsp - JSP-Servlet
About MVC 2 architecture and jsp  Sir, I want to know about MVC 2 architecture and can we bring all functionalities of servlets in jsp.What is the need of servlets when jsp can perform all functionalities .  Hi
JSF Architecture
also uses the MVC pattern. ?JSF Architecture? article in roseindia.net explains the architecture of a JSF application. Read about the topic at JSF...MVC is one of the most widely used design pattern for developing applications
online book store by using MVC architecture
and complaint with MVC architecture...online book store by using MVC architecture  Tarzan book store decided to go online to increase itsā?? revenues and provide itsā?? customers a way
Spring MVC, Spring MVC Module Tutorial
;  In this example we will give you quick overview of Spring MVC... applications based Model View Controller (MVC) architecture. What is MVC architecture? The MVC or Model View Controller architecture is famous design
Hibernate Architecture
In this tutorial we are going to describe hibernate architecture with example
Query for generating Stock Report Using MVC architecture in j2ee
Query for generating Stock Report Using MVC architecture in j2ee  help Me for query , to generate the stock report of shopping project. Considering some data (current stock=(summation of)watch Quantity in WATCHMASTER
MVC in flex
MVC in flex  Hi..... Please tell me What is MVC and how do you... application according to MVC. Thanks  Ans: Model?View?Controller (MVC) is a software architecture, currently considered an architectural pattern used
Spring MVC User Registration example
Spring MVC User Registration example  hi, I am unable to find springMVCUserRegistration example full code can u send me full code of this example   Please visit the following link: Spring MVC USer Registration
Detailed introduction to Struts 2 Architecture
Detailed introduction to Struts 2 Architecture       Struts 2 Framework Architecture In the previous section we learned about MVC framework and in this section we will learn about the different
Struts Architecture - Struts
(MVC) design pattern. It uses and extends the Java Servlet API to encourage developers to adopt an MVC architecture. Struts framework provides three key... struts architecture with flow.   Hi friend, Struts is an open source
mvc - Development process
mvc  how to write mvc structure give me some example  Hi friend, For more information on MVC Architecture visit to : http://www.roseindia.net/struts/mvc-architecture.shtml http://www.roseindia.net/struts
Understanding MVC design pattern
for specific project. The MVC architecture contains the three parts they are Model...Understanding MVC Design Pattern The MVC (Model View Controller) design pattern is used by the struts for building an applications. It makes the application
spring MVC frame work - Spring
spring MVC frame work  Example of spring MVC frame work
Hibernate Architecture
Hibernate Architecture       In this lesson you will learn the architecture of Hibernate.  The following diagram describes the high level architecture of hibernate
Struts MVC
Architecture The MVC design patterns provides a clean separation of objects... Struts MVC Struts is open source MVC framework in Java. The Struts framework... is used to develop web applications using MVC (Model-View-Controller) design
JSP Architecture, JSP Model 1 architecture, JSP Model 2 architecture
The JSP Model 2 architecture is based on the popular MVC architecture. Here Model... is the diagram of JSP Model 2 architecture: The MVC architecture is very...JSP Architecture In this section we are discussing JSP Architecture and types
Spring MVC Hello World Example
Spring MVC Hello World Example       Spring MVC Hello World Example in Spring 2.5 In this tutorial we will develop the Spring MVC Example and then run on the Tomcat server. We
Spring 2.5 MVC User Registration Example
Spring MVC User Registration example       Spring 2.5 MVC User Registration Example This tutorial shows you how to create user registration application in Spring MVC. This application
Client-Server Architecture
Client-Server Architecture       Client-server architecture can be considered... clients. In a Client/server architecture individual computers (known as clients
Spring 3.2 MVC Hibernate Example
In this section, you will learn to integrate Spring 3.2 MVC with Hibernate
JSF Architecture
JSF Architecture      JSF was developed integrating MVC design pattern so that applications can... to understand what is MVC design pattern, how MVC helps to design an application well
Spring MVC XmlViewResolver Example
://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc
Spring MVC Controller hierarchy
simplified architecture: In this Spring MVC, DispatcherServlet works... Spring MVC Controllers - Controllers hierarchy in Spring MVC      Controllers hierarchy in Spring MVC
Spring 3.2 MVC Form Handling
In this example, you will learn about handling forms in Spring 3.2 MVC
Spring 3 MVC hello world, Spring 3.0 Web MVC Example
Spring 3 MVC Hello World Example Getting stated with the Spring 3 MVC by developing first Hello World MVC example. This is the first example of writing first example in Spring MVC. After completing the tutorial you will be able
Spring MVC JDBC Example
Spring MVC JDBC Example To connect your Spring web application to the database you will have to create a DataSource and JdbcTemplate bean in your dispatcher servlet. The following is the mapping for your data source in a dispatcher
mvc
mvc   can any one tell me how to save the data in the data base sql and after saving the data how to retrieve the data according to some condition and show it in another form... iam using eclipse hibernate and java ... iam using
about MVC in java - Java Interview Questions
about MVC in java  hi, In MVC Architecute can the Model and View can communicate directly or not?  Hi friend, For read in details MVC Architecture visit to : http://www.roseindia.net/struts/mvc
Request for complete code of the Spring 2.5 MVC User Registration Example
Request for complete code of the Spring 2.5 MVC User Registration Example  Hi, The Spring 2.5 MVC User Registration Example is very helpfull... the complete code of this example or rest of the part. Best Regards, Uttam kumar
Spring 3.0 MVC Form, Spring 3.0 MVC Form Example
Spring 3 MVC Form Example In this tutorial we are going to develop Spring 3 MVC form example. This  application will help you learn the concept of Spring 3 MVC forms. After completing this tutorial you will be able to understand
Spring 3 MVC Validation Example
Spring 3 MVC Validation Example This tutorial shows you how to validate Spring 3 MVC based applications. In Spring 3 MVC annotation based controller has been added and other type of controllers are not deprecated. In this example
Jsp using mvc - JSP-Servlet
Jsp using mvc  hi I have written using mvc2 architecture, i have... in its presentation when the model changes. 1. The MVC2 architecture removes the page centric property of MVC1 architecture by separating Presentation
Spring MVC Say Hello Example
Say Hello application in Spring 2.5 MVC   ... with the development of form based application in Spring MVC. You will learn how.... Then application displays name with "Hello" message. For example we will enter
How Spring MVC Module Works
How Spring MVC Works      How Spring MVC Works? In this we will see the request flow for the spring framework... of Spring MVC module. The Spring MVC modules comes with the Spring
Model View Architecture - JSP-Interview Questions
Model View Architecture  Describe the architectural overview of Model view architecture?  Hi friend, Model-view-controller (MVC... of the application or the underlying business rules without affecting the other. In MVC
BeanNameUrlHandlerMapping example in Spring 2.5 Web MVC framework
BeanNameUrlHandlerMapping Example       BeanNameUrlHandlerMapping example in Spring 2.5 MVC framework.... In this example we will discuss about BeanNameUrlHandlerMapping that provide
Problem in Spring 3 MVC and Hibernate 3 Example tutorial source codes
Problem in Spring 3 MVC and Hibernate 3 Example tutorial source codes  I referred your tutorial "Spring 3 MVC and Hibernate 3 Example" and downloaded your source codes. I created a build.xml and built it using ant. And copied
Getting started with the Spring MVC framework.
. We will first develop a simple Spring MVC Hello World example... Spring MVC Getting Started - Getting started with Spring MVC... Spring MVC Framework In this we will quickly start developing the application
Client-Server Architecture
Client-Server Architecture       Client-server architecture can be considered... clients. In a Client/server architecture individual computers (known as clients
spring3 mvc appliation bean definition not found error
spring3 mvc appliation bean definition not found error  hi I executed spring3 mvc with annotation example after clicking on the register page I got the following error, can you suggest me how to solve. The error message
Spring web mvc 3.0 mysql project
Spring web mvc 3.0 mysql project  Hello Sir... I want a complete database connectivity web project in spring mvc 3.0..Just give me a simple example which works in netbeans IDE and tomcat server.... Its urgent..sir... Please
Spring MVC Login Example
Spring MVC Login example       Spring 2.5 MVC User Login Example This section explains you how you can make Login example using Spring MVC module. In this login example we are not connecting to any

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.