JSP Devlopment

 

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
  • Selenium with python
    Selenium with Python Training
  • As we know, that Selenium with Python Web Browser Selenium Automation is Gaining Popularity Day by Day. So many Frameworks and Tools Have arisen to get Services to Developers.

  • Deep learning course
    Deep Learning Course
  • Artificial Intelligence, Deep mastering (DL) is completely about, many levels of Representation and sort of abstraction. That guide to design a sense of Information like Images, sound and text format.

  • machine learning with python
    Machine Learning with Python Training
  • Over last few years, Big Data and analysis have come up, with Exponential and modified Direction of Business. That operate Python, emerged with a fast and strong Contender for going with Predictive Analysis.

  • Data science with R
    Data Science With R Training
  • Understanding and using Linear, non-linear regression Models and Classifying techniques for stats analysis. Hypothesis testing sample methods, to get business decisions.

  • data science with python
    Data Science with Python Training
  • Everyone starts Somewhere, first you learn basics of Every Scripting concept. Here you need complete Introduction to Data Science python libraries Concepts.

  • devops with azure
    Devops with Azure Training
  • As we Know Azure DevOps is a Bunch of Services, in guiding Developers. It contains CI/CD, pipelines, code Repositories, Visual Reporting Tools and more code management with version control.


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