JSP Devlopment

Click to rate this post!
[Total: 0 Average: 0]

 

Registration Form in JSP

For making enlistment frame, you should have a table in the database. You can compose the database rationale in JSP record, yet isolating it from the JSP page is better approach. Here, we will utilize DAO, Factory Method, DTO and Singleton configuration designs.

  • jsp
  • java
  • jsp
  • java
  • java
  • java

Example of Registration Form:

CREATE TABLE  “USER432”

(    “NAME” VARCHAR2(4000),

“EMAIL” VARCHAR2(4000),

“PASS” VARCHAR2(4000)

)/

index.jsp

<form action=”process.jsp”>

<input type=”text” name=”uname” value=”Name…” onclick=”this.value=””/><br/>

<input type=”text” name=”uemail”  value=”Email ID…” onclick=”this.value=””/><br/>

<input type=”password” name=”upass”  value=”Password…” onclick=”this.value=””/><br/>

<input type=”submit” value=”register”/>

</form>

process.jsp

<%@page import=”bean.RegisterDao”%>

<jsp:useBean id=”obj” class=”bean.User”/>

<jsp:setProperty property=”*” name=”obj”/>

<%

int status=RegisterDao.register(obj);

if(status>0)

out.print(“You are successfully registered”);

%>

User.java

public class User {  package bean;

private String uname,upass,uemail;

public String getUname() {

return uname;

}

public void setUname(String uname) {

this.uname = uname;

}  public String getUpass() {

return upass;

}  public void setUpass(String upass) {

this.upass = upass;

}

public String getUemail() {

return uemail;

}

public void setUemail(String uemail) {

this.uemail = uemail;  }

}

Provider.java

package bean;

public interface Provider {

String DRIVER=”oracle.jdbc.driver.OracleDriver”;

String CONNECTION_URL=”jdbc:oracle:thin:@localhost:1521:xe”;

String USERNAME=”system”;

String PASSWORD=”oracle”;

}

ConnectionProvider.java

package bean;

import java.sql.*;

import static bean.Provider.*;

public class ConnectionProvider {

private static Connection con=null;

static{

try{

Class.forName(DRIVER);

con=DriverManager.getConnection(CONNECTION_URL,USERNAME,PASSWORD);

}catch(Exception e){}

}

public static Connection getCon(){

return con;

}

}

RegisterDao.java:

package bean;

import java.sql.*;

public class RegisterDao {

public static int register(User u){

int status=0;

try{

Connection con=ConnectionProvider.getCon();

PreparedStatement ps=con.prepareStatement(“insert into user432 values(?,?,?)”);

ps.setString(1,u.getUname());

ps.setString(2,u.getUemail());

ps.setString(3,u.getUpass());

status=ps.executeUpdate();

}catch(Exception e){}

return status;

}

}

JAVA Tutorial Video

Login and Logout:

The DAO (Data Access Object), Factory method and DTO (Data Transfer Object) design patterns.

  • jsp
  • jsp
  • jsp
  • java
  • java
  • java
  • java

 Example:

logout.jsp  profile.jsp CREATE TABLE  “USER432”

(    “NAME” VARCHAR2(4000),

.          “EMAIL” VARCHAR2(4000),

“PASS” VARCHAR2(4000)

)

/

index.jsp:

<a href=”login.jsp”>login</a>|

<a href=”logout.jsp”>logout</a>|

<a href=”profile.jsp”>profile</a>

login.jsp:

<%@ include file=”index.jsp” %>

<hr/>

<h3>Login Form</h3>

<%

String profile_msg=(String)request.getAttribute(“profile_msg”);

if(profile_msg!=null){

out.print(profile_msg);

}

String login_msg=(String)request.getAttribute(“login_msg”);

if(login_msg!=null){

out.print(login_msg);

}

%>

<br/>

<form action=”loginprocess.jsp” method=”post”>

Email:<input type=”text” name=”email”/><br/><br/>

Password:<input type=”password” name=”password”/><br/><br/>

<input type=”submit” value=”login”/>”

</form>

loginprocess.jsp:

<%@page import=”bean.LoginDao”%>

<jsp:useBean id=”obj” class=”bean.LoginBean”/>

<jsp:setProperty property=”*” name=”obj”/>

<%

boolean status=LoginDao.validate(obj);

if(status){

out.println(“You r successfully logged in”);

session.setAttribute(“session”,”TRUE”);

}

else

{

out.print(“Sorry, email or password error”);

%>

<jsp:include page=”index.jsp”></jsp:include>

<%

}

%>

LoginBean.java:

package bean;

public class LoginBean {

private String email,pass;

public String getEmail() {

return email;

}       public void setEmail(String email) {

this.email = email;

}

public String getPass() {

return pass;

}

public void setPass(String pass) {

this.pass = pass;

}

}

Provider.java:

package bean;

public interface Provider {

String DRIVER=”oracle.jdbc.driver.OracleDriver”;

String CONNECTION_URL=”jdbc:oracle:thin:@localhost:1521:xe”;

String USERNAME=”system”;

String PASSWORD=”oracle”;

}

ConnectionProvider.java

package bean;

import java.sql.*;

import static bean.Provider.*;

public class ConnectionProvider {

private static Connection con=null;

static{

try{

Class.forName(DRIVER);

con=DriverManager.getConnection(CONNECTION_URL,USERNAME,PASSWORD);

}catch(Exception e){}

}  public static Connection getCon(){

return con;  }

}

LoginDao.java

package bean;

import java.sql.*;

public class LoginDao {

public static boolean validate(LoginBean bean){

boolean status=false;

try{

Connection con=ConnectionProvider.getCon();

PreparedStatement ps=con.prepareStatement(

“select * from user432 where email=? and pass=?”);

ps.setString(1,bean.getEmail());

ps.setString(2, bean.getPass());

ResultSet rs=ps.executeQuery();

status=rs.next();

}catch(Exception e){}

return status;

}

}

Uploading file to the server using JSP:

There are numerous approaches to transfer the document to the server. One of the path is by the MultipartRequest class. For utilizing this class you need the cos.jar document. In this illustration, we are giving the cos.jar document alongwith the code.

MultipartRequest class : It is an utility class to deal with the multipart/shape information ask. There are numerous constructors characterized in the MultipartRequest class.

Commonly used Constructors of MultipartRequest class:

  • MultipartRequest(HttpServletRequest request, String saveDirectory)
  • MultipartRequest(HttpServletRequest request, String saveDirectory, int maxPostSize)
  • MultipartRequest(HttpServletRequest request, String saveDirectory, int maxPostSize, String encoding)

index.jsp

<form action=”upload.jsp” method=”post” enctype=”multipart/form-data”>

Select File:<input type=”file” name=”fname”/><br/>

<input type=”image” src=”MainUpload.png”/>

</form>

 upload.jsp:

<%@ page import=”com.oreilly.servlet.MultipartRequest” %>

<%

MultipartRequest m = new MultipartRequest(request, “d:/new”);

out.print(“successfully uploaded”);

%>

Downloading file from the server using JSP :

In this illustration, we will download the jsp record. Be that as it may, you may download any document. For downloading the record from the server, you ought to determine the substance sort named APPLICATION/OCTET-STREAM.

index.jsp

<a href=”download.jsp”>download the jsp file</a>

download.jsp

<%

String filename = “home.jsp”;

String filepath = “e:\\”;

response.setContentType(“APPLICATION/OCTET-STREAM”);

response.setHeader(“Content-Disposition”,”attachment; filename=\”” + filename + “\””);

java.io.FileInputStream fileInputStream=new java.io.FileInputStream(filepath + filename);

int i;

while ((i=fileInputStream.read()) != -1) {

out.write(i);

}

fileInputStream.close();

%>

 

Subscribe
to our newsletter

Drop Us A Query

Trending Courses
  • Microsoft Azure Architect Technologies(AZ-300) | ITGuru
    Microsoft Azure Architect Technologies(AZ-300)
  • Azure is a great Microsoft Cloud Computing platform in providing various cloud services through online. ITGuru Certified Azure Architect certification course gives you the practical knowledge on Azure Cloud platform through real-world use cases from live experts

  • ServiceNow Admin Training | ITGuru
    ServiceNow Admin Training
  • Getting knowledge of cloud platforms like ServiceNow is essential in today’s world for the smooth running of projects in cloud platform. Turn your dream to the reality of becoming the Certified ServiceNow Administrator through ServiceNow Administration online certification Course with practical examples by live industry experts through online at ITGuru with real-world use cases.

  • Workday Financials Training | ITGuru
    Workday Financials Training
  • knowing the basics on any platform like Workday is not enough to sustain the IT industry. Hence it is essential to go beyond on Workday basics like Workday Financials training which lets you know the application of Financials management in real -world use cases from ITGuru Live Experts in a practical way.

  • Workday Training
  • An organization is considered as the best one when it offers the best benefits to the employee. Moreover, the greater the employee benefits, the greater the contribution to the organization. ITGuru let you know the practical workday Human Resource Management(HRM) features with live examples by experts

  • Python Online Course | ITGuru
    Python Online Course
  • Turn your dream into reality by ITGuru live experts with real-world use cases through practical knowledge on python online course and become the certified associate in python programming and become a master in python programming

  • Python Programming | ITGuru
    Python Programming
  • Python is the trending programming language in the IT industry. Mastering in python programming gives you more value among the people in the IT industry. Hence start today to learn python programming online by live experts with real-time uses cases at ITGuru


100% Secure Payments. All major credit & debit cards accepted.

Call Now Button