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



Home Answers Viewqa Java-Beginners MVC architecture example
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


shxrainz
MVC architecture example
2 Answer(s)      6 years and a month ago
Posted in : Java Beginners



Advertisement
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 Tutorials/Questions & Answers:
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 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
Advertisements
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
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
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
using jsp and servlets andin Mvc architecture
using jsp and servlets andin Mvc architecture  how to insert a form data in different tables, that means education details in education table, address details in address table,like that and finally if we fetch all must come
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
Problem in populating tableview with database data using javafx MVC architecture.
Problem in populating tableview with database data using javafx MVC architecture.  This code is working in simple javafx appliction without MVC architecture. Here i want to populate tableview as it is with database table data
Problem in populating tableview with database data using javafx MVC architecture.
Problem in populating tableview with database data using javafx MVC architecture.  This code is working in simple javafx appliction without MVC architecture. Here i want to populate tableview as it is with database table data
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
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
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
Hibernate Architecture
In this tutorial we are going to describe hibernate architecture with example
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
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
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
Spring 3 MVC Login Form Example with Database MySql
Spring 3 MVC Login Form Example with Database MySql  Sir i have checked your project of Spring 3 MVC Login Form Example But Sir Not able to do It with database Mysql. Can you Provide code for login with database. Thanks
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
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
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
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 Architecture
Spring Architecture Spring is a light-weight framework that is used for the development of Enterprise-ready applications. The architecture of Spring forms a layered architecture having seven modules. All modules are built over core
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
Spring MVC XmlViewResolver Example
://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc
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
 

 

 

DMCA.com