NetBeans, JSP, Servlets and Oracle

In NetBeans if you are using GlassFish Web Server, you may have to change the port number of oracle 
You can change the port number of oracle by 

1. open SQL Command Line and type connect 
username is system and 
password is as u have set up or manager
 
2. Type the below command
Exec DBMS_XDB.SETHTTPPORT(9090);  

Here 9090 is the port number ur going to change

To run any java Application code you have downloaded

When you download any java web application/project code
you will get mostly 4 folders
1. web (contains all images and .jsp files)
2. build (in build folder->web folder->WEB-INF folder->lib folder... u will find all libraries that need to be added..To know how to add libraries refer video or description below)
3. nbprojects
4. src (contains all .java files)
5. build.xml

File menu-> New Project->
Under Categories --> select Java Web
Under Application --> select Web Application
and click Next

Give a Project name: For example RMS
Project Location will tell you where ur project files are stored
Project Folder will give the folder name where ur project files are stored

click next ->next and click and Finish
==============================================
Your project name (RMS here) will be displayed on your left side pane under Projects
Under RMS four folders are already created
1. Web Pages
2. Source Packages
3. Libraries
4. Configuration Files


Copy all the .java files of the code you have downloaded(u will find in src folder->javafolder)
Click on + symbol next to Source Packages
Right click on  <default package>
and paste all the .java files you have copied

Click on + symbol next to WebPages
and delete index.html page
Now Copy all the .jsp files or all files and folders in web folder except WEB-INF folder of the downloaded code
Right click on  WebPages
and paste all the files you have copied

For database connectivity

Click on Windows menu and select services
Under Databases-> Drivers-> you will see Oracle Thin
Right Click on Oracle Thin and select Connect Using

On the New Connection Wizard Window that pops up
Change the service ID(SID) as xe or orcl (See the first video if u dont understand or refer below)
Also type the username and password u use to connect to your oracle database
and click on Test connection and to check the connectivity to the database

copy the JDBC URL:
 and click Finish

your jdbc url will under Services tab
(in my computer ) it is jdbc:oracle:thin:@localhost:1521:XE
Right click on it and click Connect
it will ask u for password and click connect

under
jdbc:oracle:thin:@localhost:1521:XE

u will see ur username of oracle and under that u will see Tables
Under Tables u will see all the tables u have created in your oracle.

Right click on jdbc:oracle:thin:@localhost:1521:XE and select properties and
copy the database Url  and type in the .java files where ever u see
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","<oracle username>","<oracle Password>"

To add libraries

Right Click on Libraries under RMS and select  Add JAR/folders and select ojbc7.jar file
and fix the errors



((To need to find ur SID of your oracle data base
Go to Oracle 10G express edition under Program files in your computer
and click on Run Sql Command line
type
connect
username: <enter ur user name>
password: <enter ur password>

and type
select instance_name from v$instance;
it will give u ur database instance name or (SID))

1. In Netbeans for database connectivity, follow the steps in the video url mentioned below. You can add ojdbc7.jar file instead of ojdc6.jar file as in the video




 

changes to be made to JSP and Servlet code to use Type 4 JDBC driver in NetBeans

1. import oracle.jdbc.OraclePreparedStatement;
import oracle.jdbc.OracleResultSet;


2. Class.forName("oracle.jdbc.OracleDriver");

3. Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr","hr");

4. OraclePreparedStatement pstmt=(OraclePreparedStatement)con.prepareStatement("select * from login where username=? and password=?");

5.  OracleResultSet rs=(OracleResultSet)pstmt.executeQuery();

6.  OracleStatement st=(OracleStatement)con.createStatement();


To maintain session , HttpSession is used. We can set the attribute of HttpSession (Ex: userid ) in the home.java file i.e, once the user logs in as shown below:
    HttpSession session=request.getSession();
    Integer I=rs.getInt(1);
    session.setAttribute("userid",I);

when u redirect to another page from home.java, the login information can be retrieved by getAttribute method in jsp and as well as servlets

In servlets:
HttpSession s=request.getSession();
 int userid=(Integer)(s.getAttribute("userid"));

In JSP:
<%  int  userid=(Integer)(session.getAttribute("userid"));%>
=========================================================
To pass information other than login information from an jsp file to servlet, we can use
<input type="hidden" name="qno" value=<%=questionno%>></input>
Here questionno is the variable whose value you can pass from jsp page to servlet

To get that information in servlet file, we can use
qno1=Integer.parseInt(request.getParameter("qno1"));

==============================================
To pass information from servlet to jsp file

 request.setAttribute("marks", marks);
 request.getRequestDispatcher("./Result.jsp").forward(request, response);

here we are passing the value in variable marks to Result.jsp

In Result.jsp file, we can get the marks as follows
int marks=(Integer)request.getAttribute("marks");
==================================

JAVA mini project code 

Web Based Recruitment Management system

Requirements

NetBeans IDE 8
Oracle 10g Express Edition
Libraries u can find in build folder->web folder->WEB-INF folder->lib folder
log4j1.2.17.jar
ojdbc7.jar

you can  download entire JAVA mini project Web Based Recruitment Management system ...from the link below

https://drive.google.com/open?id=1u5VeOv7Cdx8KhAT5vnl5KZg4j-36pF3a




1 comment:

  1. Thank you very much for the post madam. Because of this post i was able to complete my mini project.

    ReplyDelete