Web enabled Application

 Develop a solution that maps the specifications of the problem Write a report that describes the work conducted.The report should include both the description of the deliverable aswell as the process thatwas followed. In particular the report should:  1)Provide a brief analysis of the problem solution 2)Outline the key design and implementation points of the solution 3)Specify the tasks allocated to each member of the group 4)Provide an outline of the meetings that took place,if any, and themanagerial handling of the project description of project:A small private education center wants to enable student registration as well asreview of grades from the web. Each student shouldhave a registration number.If a new student wants to register then the application you develop should allowfor online registration and should record all the relevant information. A registeredstudent should be able to view the classes that areoffered in the next academicterm. For each class, the student should be informed of the title, the code, thetime and the cost. Students should be able to register to a class as long as thenumber of students that have already registered issmaller than 25. A studentshould also be able to request a view of his gradesto date. i uploaded some examples to help you i use the netbeans 7.2i want the project in netbeans 7.2 and mysqlalso i want the project full comments

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

examples/Partial Solution (part 1&2).rar

Partial Solution (part 1&2)/commentApp-part.rar

commentApp/build/web/basic.css
/*
Document : basic
Created on : Mar 12, 2013, 11:22:36 AM
Author : christoforos
Description:
Purpose of the stylesheet follows.
*/
root {
display: block;
}
#menu {
float: left;
width:180px;
padding: 0px;
font-family: Arial;
}
#menu a:link, #menu a:visited, #menu a:active {
display:block;
font-size:12px;
font-weight:bold;
text-decoration:none;
padding:4px;
color:#666600
}
#menu a:hover {
display:block;
font-size:12px;
font-weight:bold;
text-decoration:none;
color:#CCCCCC;
background-color:#666600;
}

#main {
margin-left: 200px;
font-family: Arial;
}

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

commentApp/build/web/do_register.jsp
<%-- Document : do_register Created on : Mar 12, 2013, 11:02:38 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>


<% String nm = request.getParameter("nm"); String snm = request.getParameter("snm"); String usn = request.getParameter("usn"); String pwd = request.getParameter("pwd"); User me = bean.registerUser(nm, snm, usn, pwd); if(me == null) response.sendRedirect("register.jsp?error"); else { session.setAttribute("me", me); response.sendRedirect("main.jsp"); } %>

commentApp/build/web/index.jsp
<%-- Document : index Created on : Mar 12, 2013, 10:07:01 AM Author : christoforos --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page

Login to the application to view comments

Username
Password

<% if(request.getParameter("error") != null) { out.println("

Wrong access rights

“);
}
%>

Not a user? Click here to register


commentApp/build/web/main.jsp
<%-- Document : main Created on : Mar 12, 2013, 11:13:41 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page

<% User me = (User) session.getAttribute("me"); if(me ==null) response.sendRedirect("index.jsp?error"); else { %>

Welcome <%= me.getFullName() %>!

<% } %>

commentApp/build/web/menu.jsp
<%-- Document : menu Created on : Mar 12, 2013, 11:28:58 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<% User me = (User) session.getAttribute("me"); %>
Add comment
View comments
Update my comments
<% if(me.isAdv()) { %>
Add subject
<% } %>

commentApp/build/web/META-INF/context.xml

commentApp/build/web/META-INF/MANIFEST.MF
Manifest-Version: 1.0

commentApp/build/web/proc_login.jsp
<%-- Document : proc_login Created on : Mar 12, 2013, 10:45:25 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<% String usn = request.getParameter("usn"); String pwd = request.getParameter("pwd"); User me = bean.checkLogin(usn, pwd); if(me != null) { session.setAttribute("me", me); response.sendRedirect("main.jsp"); } else { response.sendRedirect("index.jsp?error"); } %>

commentApp/build/web/register.jsp
<%-- Document : register Created on : Mar 12, 2013, 10:45:13 AM Author : christoforos --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page


Login to the application to view comments

Name
Surname
Username
Password
Retype Password


commentApp/build/web/WEB-INF/classes/.netbeans_automatic_build

commentApp/build/web/WEB-INF/classes/.netbeans_update_resources

commentApp/build/web/WEB-INF/classes/beans/Accessor.class
package beans;
public synchronized class Accessor {
public void Accessor();
public User checkLogin(String, String);
public User registerUser(String, String, String, String);
private javax.sql.DataSource getCommdb() throws javax.naming.NamingException;
}

commentApp/build/web/WEB-INF/classes/beans/User.class
package beans;
public synchronized class User {
private String name;
private String surname;
private int pk;
private boolean adv;
public void User();
public String getFullName();
public String getName();
public void setName(String);
public String getSurname();
public void setSurname(String);
public int getPk();
public void setPk(int);
public boolean isAdv();
public void setAdv(boolean);
}

commentApp/build/web/WEB-INF/web.xml

30

index.jsp

jdbc:mysql://194.42.29.147:3306/commentdb?zeroDateTimeBehavior=convertToNull
commdb
javax.sql.DataSource
Container
Shareable

commentApp/build.xml

Builds, tests, and runs the project commentApp.

commentApp/nbproject/ant-deploy.xml

commentApp/nbproject/build-impl.xml

Must set src.dir
Must set test.src.dir
Must set build.dir
Must set build.web.dir
Must set build.generated.dir
Must set dist.dir
Must set build.classes.dir
Must set dist.javadoc.dir
Must set build.test.classes.dir
Must set build.test.results.dir
Must set build.classes.excludes
Must set dist.war

The Java EE server classpath is not correctly set up – server home directory is missing.
Either open the project in the IDE and assign the server or setup the server classpath manually.
For example like this:
ant -Dj2ee.server.home=

The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}.
Either open the project in the IDE and assign the server or setup the server classpath manually.
For example like this:
ant -Duser.properties.file= (where you put the property “j2ee.platform.classpath” in a .properties file)
or ant -Dj2ee.platform.classpath= (where no properties file is used)

Must set javac.includes

No tests executed.

The libs.CopyLibs.classpath property is not set up.
This property must point to
org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part
of NetBeans IDE installation and is usually located at
/java/ant/extra folder.
Either open the project in the IDE and make sure CopyLibs library
exists or setup the property manually. For example like this:
ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar

Must set JVM to use for profiling in profiler.info.jvm
Must set profiler agent JVM arguments in profiler.info.jvmargs.agent

Must select some files in the IDE or set javac.includes

Must select some files in the IDE or set javac.jsp.includes

Must select a file in the IDE or set jsp.includes

Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable.

Launching ${browse.url}

Must select one file in the IDE or set run.class

Must select one file in the IDE or set run.class

Must select one file in the IDE or set debug.class

Must select one file in the IDE or set debug.class

Must set fix.includes

This target only works when run from inside the NetBeans IDE.

Must select some files in the IDE or set javac.includes

Some tests failed; see details above.

Must select some files in the IDE or set test.includes

Some tests failed; see details above.

Must select some files in the IDE or set test.class
Must select some method in the IDE or set test.method

Some tests failed; see details above.

Must select one file in the IDE or set test.class

Must select one file in the IDE or set test.class
Must select some method in the IDE or set test.method

commentApp/nbproject/genfiles.properties
build.xml.data.CRC32=44fe44ea
build.xml.script.CRC32=b38bd095
build.xml.stylesheet.CRC32=651128d4@1.38.1.1
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=44fe44ea
nbproject/build-impl.xml.script.CRC32=b2fdbafc
nbproject/build-impl.xml.stylesheet.CRC32=4e9cae83@1.38.1.1

commentApp/nbproject/private/private.properties
deploy.ant.properties.file=C:\\Users\\setup\\AppData\\Roaming\\NetBeans\\7.2\\tomcat70.properties
j2ee.server.home=C:/Program Files/Apache Software Foundation/Apache Tomcat 7.0.27
j2ee.server.instance=tomcat70:home=C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 7.0.27:base=apache-tomcat-7.0.27.0_base
user.properties.file=C:\\Users\\setup\\AppData\\Roaming\\NetBeans\\7.2\\build.properties

commentApp/nbproject/project.properties
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=true
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.web.dir}/WEB-INF/classes
build.classes.excludes=**/*.java,**/*.form
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
build.web.dir=${build.dir}/web
build.web.excludes=${build.classes.excludes}
client.urlPart=
compile.jsps=false
conf.dir=${source.root}/conf
debug.classpath=${build.classes.dir}:${javac.classpath}
debug.test.classpath=\
${run.test.classpath}
display.browser=true
dist.dir=dist
dist.ear.war=${dist.dir}/${war.ear.name}
dist.javadoc.dir=${dist.dir}/javadoc
dist.war=${dist.dir}/${war.name}
excludes=
includes=**
j2ee.compile.on.save=true
j2ee.copy.static.files.on.save=true
j2ee.deploy.on.save=true
j2ee.platform=1.5
j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-3.7.2.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-util.jar
j2ee.server.type=Tomcat
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.debug=true
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.5
javac.target=1.5
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.preview=true
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
lib.dir=${web base.dir}/WEB-INF/lib
no.dependencies=false
persistence.xml.dir=${conf.dir}
platform.active=default_platform
resource.dir=setup
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
# Space-separated list of JVM arguments used when running a class with a main method or a unit test
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value):
runmain.jvmargs=
source.encoding=UTF-8
source.root=src
src.dir=${source.root}/java
test.src.dir=test
war.content.additional=
war.ear.name=${war.name}
war.name=commentApp.war
web base.dir=web
webinf.dir=web/WEB-INF

commentApp/nbproject/project.xml

org.netbeans.modules.web.project

commentApp
1.6.5

commentApp/src/conf/MANIFEST.MF
Manifest-Version: 1.0

commentApp/src/java/beans/Accessor.java
commentApp/src/java/beans/Accessor.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package
 beans
;

import
 java
.
sql
.
Connection
;

import
 java
.
sql
.
PreparedStatement
;

import
 java
.
sql
.
ResultSet
;

import
 java
.
sql
.
Statement
;

import
 javax
.
naming
.
Context
;

import
 javax
.
naming
.
InitialContext
;

import
 javax
.
naming
.
NamingException
;

import
 javax
.
sql
.
DataSource
;

/**
 *
 * 
@author
 christoforos
 */

public
 
class
 
Accessor
 
{

    
public
 
User
 checkLogin
(
String
 usn
,
 
String
 pwd
)
 
{

        
/*
         * connect to database
         * select user with parameters
         * if exists initialise user object and return
         */

        
//TODO
        
try
{

            
//creates a connection to the server
            
Connection
 cn 
=
 getCommdb
().
getConnection
();

            
//prepare my sql string
            
String
 sql 
=
 
“SELECT * FROM user where usn = ? and pwd = ?”
;

            
//create prepared statement
            
PreparedStatement
 pst 
=
 cn
.
prepareStatement
(
sql
);

            
//set sql parameters
            pst
.
setString
(
1
,
 usn
);

            pst
.
setString
(
2
,
 pwd
);

            
//call the statement and retrieve results
            
ResultSet
 rs 
=
 pst
.
executeQuery
();

            
if
(
rs
.
next
())
 
{
//the usn pwd are correct
                
User
 u 
=
 
new
 
User
();

                u
.
setAdv
(
rs
.
getBoolean
(
“mode”
));

                u
.
setName
(
rs
.
getString
(
“name”
));

                u
.
setSurname
(
rs
.
getString
(
“sname”
));

                u
.
setPk
(
rs
.
getInt
(
“uid”
));

                
return
 u
;

            
}

        
}

        
catch
 
(
Exception
 e
)
 
{

            
String
 msg 
=
 e
.
getMessage
();

        
}

        
return
 
null
;

    
}

    
    
public
 
User
 registerUser
(
String
 nm
,
 
String
 snm
,
 
String
 usn
,
 
String
 pwd
)
 
{

        
/*
         check if same username exist
         * if not 
         *   insert user and return
         * else 
         *   do nothing
         */

        
try
{

            
Connection
 cn 
=
 getCommdb
().
getConnection
();

            
String
 sql 
=
 
“SELECT * FROM user WHERE usn = ?”
;

            
PreparedStatement
 pst 
=
 cn
.
prepareStatement
(
sql
);

            pst
.
setString
(
1
,
 usn
);

            
ResultSet
 rs 
=
 pst
.
executeQuery
();

            
if
(
!
rs
.
next
())
 
{

                sql 
=
 
“INSERT INTO user (name, sname, usn, pwd, mode) ”

                        
+
 
“VALUES (?, ?, ?, ?, ?)”
;

                pst 
=
 cn
.
prepareStatement
(
sql
,
 
Statement
.
RETURN_GENERATED_KEYS
);
//need this option to get pk of new record
                pst
.
setString
(
1
,
 nm
);

                pst
.
setString
(
2
,
 snm
);

                pst
.
setString
(
3
,
 usn
);

                pst
.
setString
(
4
,
 pwd
);

                pst
.
setBoolean
(
5
,
 
false
);

                pst
.
execute
();

                rs 
=
 pst
.
getGeneratedKeys
();
//returns a resultset with the generated keys of the pst execution
                rs
.
next
();

                
User
 u 
=
 
new
 
User
();

                u
.
setAdv
(
false
);

                u
.
setName
(
nm
);

                u
.
setSurname
(
snm
);

                u
.
setPk
(
rs
.
getInt
(
1
));

                
return
 u
;

            
}

        
}

        
catch
(
Exception
 e
)
 
{

            
String
 msg 
=
 e
.
getMessage
();

        
}

        
        
//TODO
        
return
 
null
;

    
}

    
private
 
DataSource
 getCommdb
()
 
throws
 
NamingException
 
{

        
Context
 c 
=
 
new
 
InitialContext
();

        
return
 
(
DataSource
)
 c
.
lookup
(
“java:comp/env/commdb”
);

    
}

    
}

commentApp/src/java/beans/User.java
commentApp/src/java/beans/User.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package
 beans
;

/**
 *
 * 
@author
 christoforos
 */

public
 
class
 
User
 
{

    
private
 
String
 name
;

    
private
 
String
 surname
;

    
private
 
int
 pk
;

    
private
 
boolean
 adv
;

    
public
 
String
 getFullName
()
 
{

        
return
 name 
+
 
” ”
 
+
 surname
;

    
}

    
    
/**
     * 
@return
 the name
     */

    
public
 
String
 getName
()
 
{

        
return
 name
;

    
}

    
/**
     * 
@param
 name the name to set
     */

    
public
 
void
 setName
(
String
 name
)
 
{

        
this
.
name 
=
 name
;

    
}

    
/**
     * 
@return
 the surname
     */

    
public
 
String
 getSurname
()
 
{

        
return
 surname
;

    
}

    
/**
     * 
@param
 surname the surname to set
     */

    
public
 
void
 setSurname
(
String
 surname
)
 
{

        
this
.
surname 
=
 surname
;

    
}

    
/**
     * 
@return
 the pk
     */

    
public
 
int
 getPk
()
 
{

        
return
 pk
;

    
}

    
/**
     * 
@param
 pk the pk to set
     */

    
public
 
void
 setPk
(
int
 pk
)
 
{

        
this
.
pk 
=
 pk
;

    
}

    
/**
     * 
@return
 the adv
     */

    
public
 
boolean
 isAdv
()
 
{

        
return
 adv
;

    
}

    
/**
     * 
@param
 adv the adv to set
     */

    
public
 
void
 setAdv
(
boolean
 adv
)
 
{

        
this
.
adv 
=
 adv
;

    
}

}

commentApp/web/basic.css
/*
Document : basic
Created on : Mar 12, 2013, 11:22:36 AM
Author : christoforos
Description:
Purpose of the stylesheet follows.
*/
root {
display: block;
}
#menu {
float: left;
width:180px;
padding: 0px;
font-family: Arial;
}
#menu a:link, #menu a:visited, #menu a:active {
display:block;
font-size:12px;
font-weight:bold;
text-decoration:none;
padding:4px;
color:#666600
}
#menu a:hover {
display:block;
font-size:12px;
font-weight:bold;
text-decoration:none;
color:#CCCCCC;
background-color:#666600;
}

#main {
margin-left: 200px;
font-family: Arial;
}

commentApp/web/do_register.jsp
<%-- Document : do_register Created on : Mar 12, 2013, 11:02:38 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>


<% String nm = request.getParameter("nm"); String snm = request.getParameter("snm"); String usn = request.getParameter("usn"); String pwd = request.getParameter("pwd"); User me = bean.registerUser(nm, snm, usn, pwd); if(me == null) response.sendRedirect("register.jsp?error"); else { session.setAttribute("me", me); response.sendRedirect("main.jsp"); } %>

commentApp/web/index.jsp
<%-- Document : index Created on : Mar 12, 2013, 10:07:01 AM Author : christoforos --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page

Login to the application to view comments

Username
Password

<% if(request.getParameter("error") != null) { out.println("

Wrong access rights

“);
}
%>

Not a user? Click here to register


commentApp/web/main.jsp
<%-- Document : main Created on : Mar 12, 2013, 11:13:41 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page

<% User me = (User) session.getAttribute("me"); if(me ==null) response.sendRedirect("index.jsp?error"); else { %>

Welcome <%= me.getFullName() %>!

<% } %>

commentApp/web/menu.jsp
<%-- Document : menu Created on : Mar 12, 2013, 11:28:58 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<% User me = (User) session.getAttribute("me"); %>
Add comment
View comments
Update my comments
<% if(me.isAdv()) { %>
Add subject
<% } %>

commentApp/web/META-INF/context.xml

commentApp/web/proc_login.jsp
<%-- Document : proc_login Created on : Mar 12, 2013, 10:45:25 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<% String usn = request.getParameter("usn"); String pwd = request.getParameter("pwd"); User me = bean.checkLogin(usn, pwd); if(me != null) { session.setAttribute("me", me); response.sendRedirect("main.jsp"); } else { response.sendRedirect("index.jsp?error"); } %>

commentApp/web/register.jsp
<%-- Document : register Created on : Mar 12, 2013, 10:45:13 AM Author : christoforos --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page


Login to the application to view comments

Name
Surname
Username
Password
Retype Password


commentApp/web/WEB-INF/web.xml

30

index.jsp

jdbc:mysql://194.42.29.147:3306/commentdb?zeroDateTimeBehavior=convertToNull
commdb
javax.sql.DataSource
Container
Shareable

Partial Solution (part 1&2)/commentApp-step2.rar

commentApp/build/web/addComment.jsp
<%-- Document : addComment Created on : 19-Mar-2013, 15:25:34 Author : setup --%>
<%@page import="java.util.List"%>
<%@page import="beans.Subject"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>





JSP Page

Enter comment details

Subject
Title
Content


commentApp/build/web/basic.css
/*
Document : basic
Created on : Mar 12, 2013, 11:22:36 AM
Author : christoforos
Description:
Purpose of the stylesheet follows.
*/
root {
display: block;
}
#menu {
float: left;
width:180px;
padding: 0px;
font-family: Arial;
}
#menu a:link, #menu a:visited, #menu a:active {
display:block;
font-size:12px;
font-weight:bold;
text-decoration:none;
padding:4px;
color:#666600
}
#menu a:hover {
display:block;
font-size:12px;
font-weight:bold;
text-decoration:none;
color:#CCCCCC;
background-color:#666600;
}

#main {
margin-left: 200px;
font-family: Arial;
}

commentApp/build/web/do_register.jsp
<%-- Document : do_register Created on : Mar 12, 2013, 11:02:38 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>


<% String nm = request.getParameter("nm"); String snm = request.getParameter("snm"); String usn = request.getParameter("usn"); String pwd = request.getParameter("pwd"); User me = bean.registerUser(nm, snm, usn, pwd); if(me == null) response.sendRedirect("register.jsp?error"); else { session.setAttribute("me", me); response.sendRedirect("main.jsp"); } %>

commentApp/build/web/index.jsp
<%-- Document : index Created on : Mar 12, 2013, 10:07:01 AM Author : christoforos --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page

Login to the application to view comments

Username
Password

<% if(request.getParameter("error") != null) { out.println("

Wrong access rights

“);
}
%>

Not a user? Click here to register


commentApp/build/web/main.jsp
<%-- Document : main Created on : Mar 12, 2013, 11:13:41 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page

<% User me = (User) session.getAttribute("me"); if(me ==null) response.sendRedirect("index.jsp?error"); else { %>

Welcome <%= me.getFullName() %>!

<% } %>

commentApp/build/web/menu.jsp
<%-- Document : menu Created on : Mar 12, 2013, 11:28:58 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<% User me = (User) session.getAttribute("me"); %>
Add comment
View comments
Update my comments
<% if(me.isAdv()) { %>
Add subject
<% } %>

commentApp/build/web/META-INF/context.xml

commentApp/build/web/META-INF/MANIFEST.MF
Manifest-Version: 1.0

commentApp/build/web/proc_addComm.jsp
<%-- Document : proc_addComm Created on : 19-Mar-2013, 15:51:09 Author : setup --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>


<% String title = request.getParameter("tlt"); String content = request.getParameter("cont"); String sbj = request.getParameter("sbj"); User me = (User) session.getAttribute("me"); boolean success = bean.addComment(me.getPk(), Integer.parseInt(sbj), title, content); if(success) response.sendRedirect("main.jsp"); else response.sendRedirect("main.jsp?error"); %>

commentApp/build/web/proc_login.jsp
<%-- Document : proc_login Created on : Mar 12, 2013, 10:45:25 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<% String usn = request.getParameter("usn"); String pwd = request.getParameter("pwd"); User me = bean.checkLogin(usn, pwd); if(me != null) { session.setAttribute("me", me); response.sendRedirect("main.jsp"); } else { response.sendRedirect("index.jsp?error"); } %>

commentApp/build/web/register.jsp
<%-- Document : register Created on : Mar 12, 2013, 10:45:13 AM Author : christoforos --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page


Login to the application to view comments

Name
Surname
Username
Password
Retype Password


commentApp/build/web/show_comments.jsp
<%-- Document : show_comments Created on : 19-Mar-2013, 16:14:47 Author : setup --%>
<%@page import="java.util.List"%>
<%@page import="beans.Comment"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>





JSP Page


<% int sbj = Integer.parseInt(request.getParameter("sbj")); List comments = bean.getComments(sbj);
%>

Relevant Comments for <%= comments.get(0).getSbjTitle() %>

<% for(Comment c : comments) { %>
From <%= c.getAuthor()%>,
<%= c.getTitle()%>
<%= c.getContent()%>


<% } %>

commentApp/build/web/viewSubjComments.jsp
<%-- Document : viewSubjComments Created on : 19-Mar-2013, 16:12:42 Author : setup --%>
<%@page import="java.util.List"%>
<%@page import="beans.Subject"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>





JSP Page

Enter comment details

Subject


commentApp/build/web/WEB-INF/classes/.netbeans_automatic_build

commentApp/build/web/WEB-INF/classes/.netbeans_update_resources

commentApp/build/web/WEB-INF/classes/beans/Accessor.class
package beans;
public synchronized class Accessor {
public void Accessor();
public java.util.List getComments(long);
public boolean addComment(int, long, String, String);
public java.util.List getSubjects();
public User checkLogin(String, String);
public User registerUser(String, String, String, String);
private javax.sql.DataSource getCommdb() throws javax.naming.NamingException;
}

commentApp/build/web/WEB-INF/classes/beans/Comment.class
package beans;
public synchronized class Comment {
private long pk;
private String sbjTitle;
private String author;
private String title;
private String content;
public void Comment();
public long getPk();
public void setPk(long);
public String getSbjTitle();
public void setSbjTitle(String);
public String getAuthor();
public void setAuthor(String);
public String getTitle();
public void setTitle(String);
public String getContent();
public void setContent(String);
}

commentApp/build/web/WEB-INF/classes/beans/Subject.class
package beans;
public synchronized class Subject {
private String name;
private long pk;
public void Subject();
public String getName();
public void setName(String);
public long getPk();
public void setPk(long);
}

commentApp/build/web/WEB-INF/classes/beans/User.class
package beans;
public synchronized class User {
private String name;
private String surname;
private int pk;
private boolean adv;
public void User();
public String getFullName();
public String getName();
public void setName(String);
public String getSurname();
public void setSurname(String);
public int getPk();
public void setPk(int);
public boolean isAdv();
public void setAdv(boolean);
}

commentApp/build/web/WEB-INF/web.xml

30

index.jsp

jdbc:mysql://194.42.29.147:3306/commentdb?zeroDateTimeBehavior=convertToNull
commdb
javax.sql.DataSource
Container
Shareable

commentApp/build.xml

Builds, tests, and runs the project commentApp.

commentApp/nbproject/ant-deploy.xml

commentApp/nbproject/build-impl.xml

Must set src.dir
Must set test.src.dir
Must set build.dir
Must set build.web.dir
Must set build.generated.dir
Must set dist.dir
Must set build.classes.dir
Must set dist.javadoc.dir
Must set build.test.classes.dir
Must set build.test.results.dir
Must set build.classes.excludes
Must set dist.war

The Java EE server classpath is not correctly set up – server home directory is missing.
Either open the project in the IDE and assign the server or setup the server classpath manually.
For example like this:
ant -Dj2ee.server.home=

The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}.
Either open the project in the IDE and assign the server or setup the server classpath manually.
For example like this:
ant -Duser.properties.file= (where you put the property “j2ee.platform.classpath” in a .properties file)
or ant -Dj2ee.platform.classpath= (where no properties file is used)

Must set javac.includes

No tests executed.

The libs.CopyLibs.classpath property is not set up.
This property must point to
org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part
of NetBeans IDE installation and is usually located at
/java/ant/extra folder.
Either open the project in the IDE and make sure CopyLibs library
exists or setup the property manually. For example like this:
ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar

Must set JVM to use for profiling in profiler.info.jvm
Must set profiler agent JVM arguments in profiler.info.jvmargs.agent

Must select some files in the IDE or set javac.includes

Must select some files in the IDE or set javac.jsp.includes

Must select a file in the IDE or set jsp.includes

Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable.

Launching ${browse.url}

Must select one file in the IDE or set run.class

Must select one file in the IDE or set run.class

Must select one file in the IDE or set debug.class

Must select one file in the IDE or set debug.class

Must set fix.includes

This target only works when run from inside the NetBeans IDE.

Must select some files in the IDE or set javac.includes

Some tests failed; see details above.

Must select some files in the IDE or set test.includes

Some tests failed; see details above.

Must select some files in the IDE or set test.class
Must select some method in the IDE or set test.method

Some tests failed; see details above.

Must select one file in the IDE or set test.class

Must select one file in the IDE or set test.class
Must select some method in the IDE or set test.method

commentApp/nbproject/genfiles.properties
build.xml.data.CRC32=44fe44ea
build.xml.script.CRC32=b38bd095
build.xml.stylesheet.CRC32=651128d4@1.38.1.1
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=44fe44ea
nbproject/build-impl.xml.script.CRC32=b2fdbafc
nbproject/build-impl.xml.stylesheet.CRC32=4e9cae83@1.38.1.1

commentApp/nbproject/private/private.properties
deploy.ant.properties.file=C:\\Users\\setup\\AppData\\Roaming\\NetBeans\\7.2\\tomcat70.properties
j2ee.server.domain=C:/Users/setup/AppData/Roaming/NetBeans/7.2/apache-tomcat-7.0.27.0_base
j2ee.server.home=C:/Program Files/Apache Software Foundation/Apache Tomcat 7.0.27
j2ee.server.instance=tomcat70:home=C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 7.0.27:base=apache-tomcat-7.0.27.0_base
user.properties.file=C:\\Users\\setup\\AppData\\Roaming\\NetBeans\\7.2\\build.properties

commentApp/nbproject/project.properties
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=true
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.web.dir}/WEB-INF/classes
build.classes.excludes=**/*.java,**/*.form
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
build.web.dir=${build.dir}/web
build.web.excludes=${build.classes.excludes}
client.urlPart=
compile.jsps=false
conf.dir=${source.root}/conf
debug.classpath=${build.classes.dir}:${javac.classpath}
debug.test.classpath=\
${run.test.classpath}
display.browser=true
dist.dir=dist
dist.ear.war=${dist.dir}/${war.ear.name}
dist.javadoc.dir=${dist.dir}/javadoc
dist.war=${dist.dir}/${war.name}
excludes=
includes=**
j2ee.compile.on.save=true
j2ee.copy.static.files.on.save=true
j2ee.deploy.on.save=true
j2ee.platform=1.5
j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-3.7.2.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/mysql-connector-java-5.1.18-bin.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-util.jar
j2ee.server.type=Tomcat
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.debug=true
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.5
javac.target=1.5
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.preview=true
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
lib.dir=${web base.dir}/WEB-INF/lib
no.dependencies=false
persistence.xml.dir=${conf.dir}
platform.active=default_platform
resource.dir=setup
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
# Space-separated list of JVM arguments used when running a class with a main method or a unit test
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value):
runmain.jvmargs=
source.encoding=UTF-8
source.root=src
src.dir=${source.root}/java
test.src.dir=test
war.content.additional=
war.ear.name=${war.name}
war.name=commentApp.war
web base.dir=web
webinf.dir=web/WEB-INF

commentApp/nbproject/project.xml

org.netbeans.modules.web.project

commentApp
1.6.5

commentApp/src/conf/MANIFEST.MF
Manifest-Version: 1.0

commentApp/src/java/beans/Accessor.java
commentApp/src/java/beans/Accessor.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package
 beans
;

import
 java
.
sql
.
Connection
;

import
 java
.
sql
.
PreparedStatement
;

import
 java
.
sql
.
ResultSet
;

import
 java
.
sql
.
Statement
;

import
 java
.
util
.
ArrayList
;

import
 java
.
util
.
List
;

import
 javax
.
naming
.
Context
;

import
 javax
.
naming
.
InitialContext
;

import
 javax
.
naming
.
NamingException
;

import
 javax
.
sql
.
DataSource
;

/**
 *
 * 
@author
 christoforos
 */

public
 
class
 
Accessor
 
{

    
    
public
 
List
< Comment >
 getComments
(
long
 sbj
)
 
{

        
try
{

            
Connection
 cn 
=
 getCommdb
().
getConnection
();

            
String
 sql 
=
 
“SELECT c.cid, c.title, c.content, u.name, u.sname, s.subj_title”

                    
+
 
” FROM comment c INNER JOIN user u on u.uid = c.user”

                    
+
 
” INNER JOIN subject s on s.sid = c.subject”

                    
+
 
” WHERE s.sid = ?”
;

            
PreparedStatement
 pst 
=
 cn
.
prepareStatement
(
sql
);

            pst
.
setLong
(
1
,
 sbj
);

            
ResultSet
 rs 
=
 pst
.
executeQuery
();

            
ArrayList
< Comment >
 comments 
=
 
new
 
ArrayList
< Comment >
();

            
while
(
rs
.
next
())
 
{

                
Comment
 c 
=
 
new
 
Comment
();

                c
.
setAuthor
(
rs
.
getString
(
“name”
)
 
+
 
” ”
 
+
 rs
.
getString
(
“sname”
));

                c
.
setContent
(
rs
.
getString
(
“content”
));

                c
.
setPk
(
rs
.
getLong
(
“cid”
));

                c
.
setSbjTitle
(
rs
.
getString
(
“subj_title”
));

                c
.
setTitle
(
rs
.
getString
(
“title”
));

                comments
.
add
(
c
);

            
}

            
return
 comments
;

        
}

        
catch
(
Exception
 e
)
 
{}

        
return
 
null
;

    
}

    
    
public
 
boolean
 addComment
(
int
 user
,
 
long
 subject
,
 
String
 title
,
 
String
 content
)
 
{

        
try
 
{

            
Connection
 cn 
=
 getCommdb
().
getConnection
();

            
String
 sql 
=
 
“INSERT INTO comment (user, subject, title, content) ”

                    
+
 
“VALUES (?, ?, ?, ?) ”
;

            
PreparedStatement
 pst 
=
 cn
.
prepareStatement
(
sql
);

            pst
.
setInt
(
1
,
 user
);

            pst
.
setLong
(
2
,
 subject
);

            pst
.
setString
(
3
,
 title
);

            pst
.
setString
(
4
,
 content
);

            pst
.
execute
();

            
return
 
true
;

        
}

        
catch
(
Exception
 e
)
 
{}

        
return
 
false
;

    
}

    
public
 
List
< Subject >
 getSubjects
()
 
{

        
try
 
{

            
Connection
 cn 
=
 getCommdb
().
getConnection
();

            
String
 sql 
=
 
“SELECT * FROM subject”
;

            
PreparedStatement
 pst 
=
 cn
.
prepareStatement
(
sql
);

            
ResultSet
 rs 
=
 pst
.
executeQuery
();

            
ArrayList
< Subject >
 ls 
=
 
new
 
ArrayList
< Subject >
();

            
while
(
rs
.
next
())
 
{

                
Subject
 s 
=
 
new
 
Subject
();

                s
.
setPk
(
rs
.
getLong
(
“sid”
));

                s
.
setName
(
rs
.
getString
(
“subj_title”
));

                ls
.
add
(
s
);

            
}

            
return
 ls
;

        
}

        
catch
 
(
Exception
 e
)
 
{

        
}

        
return
 
null
;

    
}

    
    
public
 
User
 checkLogin
(
String
 usn
,
 
String
 pwd
)
 
{

        
/*
         * connect to database
         * select user with parameters
         * if exists initialise user object and return
         */

        
//TODO
        
try
{

            
//creates a connection to the server
            
Connection
 cn 
=
 getCommdb
().
getConnection
();

            
//prepare my sql string
            
String
 sql 
=
 
“SELECT * FROM user where usn = ? and pwd = ?”
;

            
//create prepared statement
            
PreparedStatement
 pst 
=
 cn
.
prepareStatement
(
sql
);

            
//set sql parameters
            pst
.
setString
(
1
,
 usn
);

            pst
.
setString
(
2
,
 pwd
);

            
//call the statement and retrieve results
            
ResultSet
 rs 
=
 pst
.
executeQuery
();

            
if
(
rs
.
next
())
 
{
//the usn pwd are correct
                
User
 u 
=
 
new
 
User
();

                u
.
setAdv
(
rs
.
getBoolean
(
“mode”
));

                u
.
setName
(
rs
.
getString
(
“name”
));

                u
.
setSurname
(
rs
.
getString
(
“sname”
));

                u
.
setPk
(
rs
.
getInt
(
“uid”
));

                
return
 u
;

            
}

        
}

        
catch
 
(
Exception
 e
)
 
{

            
String
 msg 
=
 e
.
getMessage
();

        
}

        
return
 
null
;

    
}

    
    
public
 
User
 registerUser
(
String
 nm
,
 
String
 snm
,
 
String
 usn
,
 
String
 pwd
)
 
{

        
/*
         check if same username exist
         * if not 
         *   insert user and return
         * else 
         *   do nothing
         */

        
try
{

            
Connection
 cn 
=
 getCommdb
().
getConnection
();

            
String
 sql 
=
 
“SELECT * FROM user WHERE usn = ?”
;

            
PreparedStatement
 pst 
=
 cn
.
prepareStatement
(
sql
);

            pst
.
setString
(
1
,
 usn
);

            
ResultSet
 rs 
=
 pst
.
executeQuery
();

            
if
(
!
rs
.
next
())
 
{

                sql 
=
 
“INSERT INTO user (name, sname, usn, pwd, mode) ”

                        
+
 
“VALUES (?, ?, ?, ?, ?)”
;

                pst 
=
 cn
.
prepareStatement
(
sql
,
 
Statement
.
RETURN_GENERATED_KEYS
);
//need this option to get pk of new record
                pst
.
setString
(
1
,
 nm
);

                pst
.
setString
(
2
,
 snm
);

                pst
.
setString
(
3
,
 usn
);

                pst
.
setString
(
4
,
 pwd
);

                pst
.
setBoolean
(
5
,
 
false
);

                pst
.
execute
();

                rs 
=
 pst
.
getGeneratedKeys
();
//returns a resultset with the generated keys of the pst execution
                rs
.
next
();

                
User
 u 
=
 
new
 
User
();

                u
.
setAdv
(
false
);

                u
.
setName
(
nm
);

                u
.
setSurname
(
snm
);

                u
.
setPk
(
rs
.
getInt
(
1
));

                
return
 u
;

            
}

        
}

        
catch
(
Exception
 e
)
 
{

            
String
 msg 
=
 e
.
getMessage
();

        
}

        
        
//TODO
        
return
 
null
;

    
}

    
private
 
DataSource
 getCommdb
()
 
throws
 
NamingException
 
{

        
Context
 c 
=
 
new
 
InitialContext
();

        
return
 
(
DataSource
)
 c
.
lookup
(
“java:comp/env/commdb”
);

    
}

    
}

commentApp/src/java/beans/Comment.java
commentApp/src/java/beans/Comment.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package
 beans
;

/**
 *
 * 
@author
 setup
 */

public
 
class
 
Comment
 
{

    
private
 
long
 pk
;

    
private
 
String
 sbjTitle
;

    
private
 
String
 author
;

    
private
 
String
 title
;

    
private
 
String
 content
;

    
/**
     * 
@return
 the pk
     */

    
public
 
long
 getPk
()
 
{

        
return
 pk
;

    
}

    
/**
     * 
@param
 pk the pk to set
     */

    
public
 
void
 setPk
(
long
 pk
)
 
{

        
this
.
pk 
=
 pk
;

    
}

    
/**
     * 
@return
 the sbjTitle
     */

    
public
 
String
 getSbjTitle
()
 
{

        
return
 sbjTitle
;

    
}

    
/**
     * 
@param
 sbjTitle the sbjTitle to set
     */

    
public
 
void
 setSbjTitle
(
String
 sbjTitle
)
 
{

        
this
.
sbjTitle 
=
 sbjTitle
;

    
}

    
/**
     * 
@return
 the author
     */

    
public
 
String
 getAuthor
()
 
{

        
return
 author
;

    
}

    
/**
     * 
@param
 author the author to set
     */

    
public
 
void
 setAuthor
(
String
 author
)
 
{

        
this
.
author 
=
 author
;

    
}

    
/**
     * 
@return
 the title
     */

    
public
 
String
 getTitle
()
 
{

        
return
 title
;

    
}

    
/**
     * 
@param
 title the title to set
     */

    
public
 
void
 setTitle
(
String
 title
)
 
{

        
this
.
title 
=
 title
;

    
}

    
/**
     * 
@return
 the content
     */

    
public
 
String
 getContent
()
 
{

        
return
 content
;

    
}

    
/**
     * 
@param
 content the content to set
     */

    
public
 
void
 setContent
(
String
 content
)
 
{

        
this
.
content 
=
 content
;

    
}

}

commentApp/src/java/beans/Subject.java
commentApp/src/java/beans/Subject.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package
 beans
;

/**
 *
 * 
@author
 setup
 */

public
 
class
 
Subject
 
{

    
private
 
String
 name
;

    
private
 
long
 pk
;

    
/**
     * 
@return
 the name
     */

    
public
 
String
 getName
()
 
{

        
return
 name
;

    
}

    
/**
     * 
@param
 name the name to set
     */

    
public
 
void
 setName
(
String
 name
)
 
{

        
this
.
name 
=
 name
;

    
}

    
/**
     * 
@return
 the pk
     */

    
public
 
long
 getPk
()
 
{

        
return
 pk
;

    
}

    
/**
     * 
@param
 pk the pk to set
     */

    
public
 
void
 setPk
(
long
 pk
)
 
{

        
this
.
pk 
=
 pk
;

    
}

}

commentApp/src/java/beans/User.java
commentApp/src/java/beans/User.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package
 beans
;

/**
 *
 * 
@author
 christoforos
 */

public
 
class
 
User
 
{

    
private
 
String
 name
;

    
private
 
String
 surname
;

    
private
 
int
 pk
;

    
private
 
boolean
 adv
;

    
public
 
String
 getFullName
()
 
{

        
return
 name 
+
 
” ”
 
+
 surname
;

    
}

    
    
/**
     * 
@return
 the name
     */

    
public
 
String
 getName
()
 
{

        
return
 name
;

    
}

    
/**
     * 
@param
 name the name to set
     */

    
public
 
void
 setName
(
String
 name
)
 
{

        
this
.
name 
=
 name
;

    
}

    
/**
     * 
@return
 the surname
     */

    
public
 
String
 getSurname
()
 
{

        
return
 surname
;

    
}

    
/**
     * 
@param
 surname the surname to set
     */

    
public
 
void
 setSurname
(
String
 surname
)
 
{

        
this
.
surname 
=
 surname
;

    
}

    
/**
     * 
@return
 the pk
     */

    
public
 
int
 getPk
()
 
{

        
return
 pk
;

    
}

    
/**
     * 
@param
 pk the pk to set
     */

    
public
 
void
 setPk
(
int
 pk
)
 
{

        
this
.
pk 
=
 pk
;

    
}

    
/**
     * 
@return
 the adv
     */

    
public
 
boolean
 isAdv
()
 
{

        
return
 adv
;

    
}

    
/**
     * 
@param
 adv the adv to set
     */

    
public
 
void
 setAdv
(
boolean
 adv
)
 
{

        
this
.
adv 
=
 adv
;

    
}

}

commentApp/web/addComment.jsp
<%-- Document : addComment Created on : 19-Mar-2013, 15:25:34 Author : setup --%>
<%@page import="java.util.List"%>
<%@page import="beans.Subject"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>





JSP Page

Enter comment details

Subject
Title
Content


commentApp/web/basic.css
/*
Document : basic
Created on : Mar 12, 2013, 11:22:36 AM
Author : christoforos
Description:
Purpose of the stylesheet follows.
*/
root {
display: block;
}
#menu {
float: left;
width:180px;
padding: 0px;
font-family: Arial;
}
#menu a:link, #menu a:visited, #menu a:active {
display:block;
font-size:12px;
font-weight:bold;
text-decoration:none;
padding:4px;
color:#666600
}
#menu a:hover {
display:block;
font-size:12px;
font-weight:bold;
text-decoration:none;
color:#CCCCCC;
background-color:#666600;
}

#main {
margin-left: 200px;
font-family: Arial;
}

commentApp/web/do_register.jsp
<%-- Document : do_register Created on : Mar 12, 2013, 11:02:38 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>


<% String nm = request.getParameter("nm"); String snm = request.getParameter("snm"); String usn = request.getParameter("usn"); String pwd = request.getParameter("pwd"); User me = bean.registerUser(nm, snm, usn, pwd); if(me == null) response.sendRedirect("register.jsp?error"); else { session.setAttribute("me", me); response.sendRedirect("main.jsp"); } %>

commentApp/web/index.jsp
<%-- Document : index Created on : Mar 12, 2013, 10:07:01 AM Author : christoforos --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page

Login to the application to view comments

Username
Password

<% if(request.getParameter("error") != null) { out.println("

Wrong access rights

“);
}
%>

Not a user? Click here to register


commentApp/web/main.jsp
<%-- Document : main Created on : Mar 12, 2013, 11:13:41 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page

<% User me = (User) session.getAttribute("me"); if(me ==null) response.sendRedirect("index.jsp?error"); else { %>

Welcome <%= me.getFullName() %>!

<% } %>

commentApp/web/menu.jsp
<%-- Document : menu Created on : Mar 12, 2013, 11:28:58 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<% User me = (User) session.getAttribute("me"); %>
Add comment
View comments
Update my comments
<% if(me.isAdv()) { %>
Add subject
<% } %>

commentApp/web/META-INF/context.xml

commentApp/web/proc_addComm.jsp
<%-- Document : proc_addComm Created on : 19-Mar-2013, 15:51:09 Author : setup --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>


<% String title = request.getParameter("tlt"); String content = request.getParameter("cont"); String sbj = request.getParameter("sbj"); User me = (User) session.getAttribute("me"); boolean success = bean.addComment(me.getPk(), Integer.parseInt(sbj), title, content); if(success) response.sendRedirect("main.jsp"); else response.sendRedirect("main.jsp?error"); %>

commentApp/web/proc_login.jsp
<%-- Document : proc_login Created on : Mar 12, 2013, 10:45:25 AM Author : christoforos --%>
<%@page import="beans.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<% String usn = request.getParameter("usn"); String pwd = request.getParameter("pwd"); User me = bean.checkLogin(usn, pwd); if(me != null) { session.setAttribute("me", me); response.sendRedirect("main.jsp"); } else { response.sendRedirect("index.jsp?error"); } %>

commentApp/web/register.jsp
<%-- Document : register Created on : Mar 12, 2013, 10:45:13 AM Author : christoforos --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page


Login to the application to view comments

Name
Surname
Username
Password
Retype Password


commentApp/web/show_comments.jsp
<%-- Document : show_comments Created on : 19-Mar-2013, 16:14:47 Author : setup --%>
<%@page import="java.util.List"%>
<%@page import="beans.Comment"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>





JSP Page


<% int sbj = Integer.parseInt(request.getParameter("sbj")); List comments = bean.getComments(sbj);
%>

Relevant Comments for <%= comments.get(0).getSbjTitle() %>

<% for(Comment c : comments) { %>
From <%= c.getAuthor()%>,
<%= c.getTitle()%>
<%= c.getContent()%>


<% } %>

commentApp/web/viewSubjComments.jsp
<%-- Document : viewSubjComments Created on : 19-Mar-2013, 16:12:42 Author : setup --%>
<%@page import="java.util.List"%>
<%@page import="beans.Subject"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>





JSP Page

Enter comment details

Subject


commentApp/web/WEB-INF/web.xml

30

index.jsp

jdbc:mysql://194.42.29.147:3306/commentdb?zeroDateTimeBehavior=convertToNull
commdb
javax.sql.DataSource
Container
Shareable

Partial Solution (part 1&2)/commentDB_20130319_1659.sql
— MySQL Administrator dump 1.4

— ——————————————————
— Server version 5.1.45-community

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=’NO_AUTO_VALUE_ON_ZERO’ */;


— Create schema commentdb

CREATE DATABASE IF NOT EXISTS commentdb;
USE commentdb;

— Definition of table `comment`

DROP TABLE IF EXISTS `comment`;
CREATE TABLE `comment` (
`cid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user` int(10) unsigned NOT NULL,
`subject` int(10) unsigned NOT NULL,
`title` varchar(45) NOT NULL,
`content` text NOT NULL,
PRIMARY KEY (`cid`),
KEY `FK_user` (`user`),
KEY `FK_subj` (`subject`),
CONSTRAINT `FK_subj` FOREIGN KEY (`subject`) REFERENCES `subject` (`sid`),
CONSTRAINT `FK_user` FOREIGN KEY (`user`) REFERENCES `user` (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

— Dumping data for table `comment`

/*!40000 ALTER TABLE `comment` DISABLE KEYS */;
INSERT INTO `comment` (`cid`,`user`,`subject`,`title`,`content`) VALUES
(1,1,2,’m-tier’,’This looks involved but it is logical. i just need to practice’),
(2,1,1,’Racket’,’I like functional programming. it\’s cool’),
(3,13,1,’Hi’,’I love JAVA!!!’),
(4,14,2,”,”),
(5,1,4,’none’,’pafos ole’),
(6,1,2,’ALO’,’Re kostaki na sou pw ena anekdoto?’),
(7,1,2,’com2′,”);
/*!40000 ALTER TABLE `comment` ENABLE KEYS */;


— Definition of table `subject`

DROP TABLE IF EXISTS `subject`;
CREATE TABLE `subject` (
`sid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`subj_title` varchar(45) NOT NULL,
`descr` text NOT NULL,
PRIMARY KEY (`sid`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

— Dumping data for table `subject`

/*!40000 ALTER TABLE `subject` DISABLE KEYS */;
INSERT INTO `subject` (`sid`,`subj_title`,`descr`) VALUES
(1,’Programming Languages’,’Discussion on various aspects of programming languages and comparison of features found in them’),
(2,’Web Development’,’Discussion on server side and client side programming advances’),
(3,’Optimization’,’Discussion on combinatorial optimization problems’),
(4,’Supply Chain Management’,’Discussion on SCM and OM practices’);
/*!40000 ALTER TABLE `subject` ENABLE KEYS */;


— Definition of table `user`

DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`uid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`sname` varchar(45) NOT NULL,
`usn` varchar(45) NOT NULL,
`pwd` varchar(45) NOT NULL,
`mode` tinyint(1) NOT NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=latin1;

— Dumping data for table `user`

/*!40000 ALTER TABLE `user` DISABLE KEYS */;
INSERT INTO `user` (`uid`,`name`,`sname`,`usn`,`pwd`,`mode`) VALUES
(1,’Maria’,’Antoniou’,’user1′,’1234′,0),
(2,’Andreas’,’Nicolaou’,’user2′,’5678′,0),
(3,’Christoforos’,’Charalambous’,’user3′,’something’,1),
(12,’Marios’,’Koshiaris’,’whatever’,’qwe’,0),
(13,’blabla’,”,’blabla’,’1234′,0),
(14,’Marios’,’Andreou’,’marios’,’omonoia’,0);
/*!40000 ALTER TABLE `user` ENABLE KEYS */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

examples/Transaction application example.rar

Transaction application example/bankDB.sql
— MySQL Administrator dump 1.4

— ——————————————————
— Server version 5.1.45-community

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=’NO_AUTO_VALUE_ON_ZERO’ */;


— Create schema bank

CREATE DATABASE IF NOT EXISTS bank;
USE bank;

— Definition of table `account`

DROP TABLE IF EXISTS `account`;
CREATE TABLE `account` (
`aid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`aNum` int(10) unsigned NOT NULL,
`pin` int(10) unsigned NOT NULL,
`balance` int(10) unsigned NOT NULL,
`limit` int(10) unsigned NOT NULL,
PRIMARY KEY (`aid`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

— Dumping data for table `account`

/*!40000 ALTER TABLE `account` DISABLE KEYS */;
INSERT INTO `account` (`aid`,`aNum`,`pin`,`balance`,`limit`) VALUES
(1,123,9999,110,100),
(2,456,1111,5000,300);
/*!40000 ALTER TABLE `account` ENABLE KEYS */;


— Definition of table `log`

DROP TABLE IF EXISTS `log`;
CREATE TABLE `log` (
`lid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`account` int(10) unsigned NOT NULL,
`on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`amount` int(10) unsigned NOT NULL,
PRIMARY KEY (`lid`),
KEY `FK_log_1` (`account`),
CONSTRAINT `FK_log_1` FOREIGN KEY (`account`) REFERENCES `account` (`aid`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

— Dumping data for table `log`

/*!40000 ALTER TABLE `log` DISABLE KEYS */;
INSERT INTO `log` (`lid`,`account`,`on`,`amount`) VALUES
(1,1,’2011-04-06 16:10:46′,20),
(2,1,’2011-04-06 16:16:38′,50),
(3,1,’2011-04-06 16:22:10′,20);
/*!40000 ALTER TABLE `log` ENABLE KEYS */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

Transaction application example/transEx.rar

transEx/build/web/checkLogin.jsp
<%-- read the accid and the pin from the request use the function in the bean to see if it is ok if ok save my account in the session go to the withraw page else go to login with an error message --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import = "pack.Account" %>

<%! pack.Accessor oracle123 = new pack.Accessor(); %>
<% String acNum = request.getParameter("acnum"); String pin = request.getParameter("pin"); Account me = oracle.getAccount(Integer.parseInt(acNum), Integer.parseInt(pin) ); if(me != null) { session.setAttribute("me", me); response.sendRedirect("withdrawal.jsp"); } else { %>



<% } %>

transEx/build/web/doWithdraw.jsp
<%-- check if balance is sufficient if it is do transaction else show error --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import = "pack.Account" %>


<% String amount = request.getParameter("amount"); Account me = (Account) session.getAttribute("me"); if(oracle.checkBalance(Integer.parseInt(amount), me)) { oracle.makeWithdrawal(Integer.parseInt(amount), me.getId()); %>



<% } else { %>



<% } %>

transEx/build/web/login.jsp
<%-- Document : index Created on : Apr 6, 2011, 3:29:28 PM Author : christoforos --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page

Put your credentials

Account Number
Pin

<% String msg = request.getParameter("msg"); if(msg != null) out.println(msg); %>


transEx/build/web/META-INF/context.xml

transEx/build/web/META-INF/MANIFEST.MF
Manifest-Version: 1.0

transEx/build/web/WEB-INF/classes/.netbeans_automatic_build

transEx/build/web/WEB-INF/classes/.netbeans_update_resources

transEx/build/web/WEB-INF/classes/pack/Accessor.class
package pack;
public synchronized class Accessor {
public void Accessor();
public Account getAccount(int, int);
public boolean checkBalance(int, Account);
public void makeWithdrawal(int, int);
private javax.sql.DataSource getBankDB() throws javax.naming.NamingException;
}

transEx/build/web/WEB-INF/classes/pack/Account.class
package pack;
public synchronized class Account {
private int id;
private int acNum;
private int pin;
private int balance;
private int limit;
public void Account();
public int getId();
public void setId(int);
public int getAcNum();
public void setAcNum(int);
public int getPin();
public void setPin(int);
public int getBalance();
public void setBalance(int);
public int getLimit();
public void setLimit(int);
}

transEx/build/web/WEB-INF/web.xml

30

index.jsp

jdbc:mysql://localhost:3306/bank
bankDB
javax.sql.DataSource
Container
Shareable

transEx/build/web/withdrawal.jsp
<%-- Document : withdrawal Created on : Apr 6, 2011, 3:30:14 PM Author : christoforos --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page

How much to withdraw



<% String msg = request.getParameter("msg"); if(msg != null) out.println(msg); %>

transEx/build.xml

Builds, tests, and runs the project transEx.

transEx/nbproject/ant-deploy.xml

transEx/nbproject/build-impl.xml

Must set src.dir
Must set test.src.dir
Must set build.dir
Must set build.web.dir
Must set build.generated.dir
Must set dist.dir
Must set build.classes.dir
Must set dist.javadoc.dir
Must set build.test.classes.dir
Must set build.test.results.dir
Must set build.classes.excludes
Must set dist.war

The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}.
Either open the project in the IDE and assign the server or setup the server classpath manually.
For example like this:
ant -Duser.properties.file= (where you put the property “j2ee.platform.classpath” in a .properties file)
or ant -Dj2ee.platform.classpath= (where no properties file is used)

The libs.CopyLibs.classpath property is not set up.
This property must point to
org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part
of NetBeans IDE installation and is usually located at
/java/ant/extra folder.
Either open the project in the IDE and make sure CopyLibs library
exists or setup the property manually. For example like this:
ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar

Must select some files in the IDE or set javac.includes

Must select some files in the IDE or set javac.jsp.includes

Must select a file in the IDE or set jsp.includes

Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable.

Launching ${browse.url}

Must select one file in the IDE or set run.class

Must select one file in the IDE or set run.class

Must select one file in the IDE or set debug.class

Must select one file in the IDE or set debug.class

Must set fix.includes

Must select some files in the IDE or set javac.includes

Some tests failed; see details above.

Must select some files in the IDE or set test.includes

Some tests failed; see details above.

Must select one file in the IDE or set test.class

transEx/nbproject/genfiles.properties
build.xml.data.CRC32=17a87734
build.xml.script.CRC32=7cfeaa0a
build.xml.stylesheet.CRC32=c0ebde35@1.21.1.1
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=17a87734
nbproject/build-impl.xml.script.CRC32=84287aed
nbproject/build-impl.xml.stylesheet.CRC32=b139b33b@1.21.1.1

transEx/nbproject/private/private.properties
deploy.ant.properties.file=C:\\Users\\christoforos\\.netbeans\\6.8\\tomcat60.properties
j2ee.platform.classpath=C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\annotations-api.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\catalina-ant.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\catalina-ha.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\catalina-tribes.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\catalina.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\el-api.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\jasper-el.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\jasper.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\jsp-api.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\mysql-connector-java-5.1.6-bin.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\servlet-api.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\tomcat-coyote.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\tomcat-dbcp.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\tomcat-i18n-es.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\tomcat-i18n-fr.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\lib\\tomcat-i18n-ja.jar:C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20\\bin\\tomcat-juli.jar
j2ee.server.instance=tomcat60:home=C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.20:base=apache-tomcat-6.0.20_base
jaxbwiz.endorsed.dirs=C:\\Program Files\\NetBeans 6.8\\ide12\\modules\\ext\\jaxb\\api
user.properties.file=C:\\Users\\christoforos\\.netbeans\\6.8\\build.properties

transEx/nbproject/private/private.xml

transEx/nbproject/project.properties
build.classes.dir=${build.web.dir}/WEB-INF/classes
build.classes.excludes=**/*.java,**/*.form
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
build.web.dir=${build.dir}/web
build.web.excludes=${build.classes.excludes}
client.urlPart=
compile.jsps=false
conf.dir=${source.root}/conf
debug.classpath=${build.classes.dir}:${javac.classpath}
debug.test.classpath=\
${run.test.classpath}
display.browser=true
dist.dir=dist
dist.ear.war=${dist.dir}/${war.ear.name}
dist.javadoc.dir=${dist.dir}/javadoc
dist.war=${dist.dir}/${war.name}
excludes=
includes=**
j2ee.deploy.on.save=true
j2ee.platform=1.5
j2ee.server.type=Tomcat60
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.debug=true
javac.deprecation=false
javac.source=1.5
javac.target=1.5
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
${libs.junit.classpath}:\
${libs.junit_4.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.preview=true
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
jaxbwiz.endorsed.dirs=”${netbeans.home}/../ide12/modules/ext/jaxb/api”
jspcompilation.classpath=${jspc.classpath}:${javac.classpath}
lib.dir=${web base.dir}/WEB-INF/lib
no.dependencies=false
persistence.xml.dir=${conf.dir}
platform.active=default_platform
resource.dir=setup
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
# Space-separated list of JVM arguments used when running a class with a main method or a unit test
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value):
runmain.jvmargs=
source.encoding=UTF-8
source.root=src
src.dir=${source.root}/java
test.src.dir=test
war.content.additional=
war.ear.name=transEx.war
war.name=transEx.war
web base.dir=web
webinf.dir=web/WEB-INF

transEx/nbproject/project.xml

org.netbeans.modules.web.project

transEx
1.6.5

transEx/src/conf/MANIFEST.MF
Manifest-Version: 1.0

transEx/src/java/pack/Accessor.java
transEx/src/java/pack/Accessor.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package
 pack
;

import
 java
.
sql
.
Connection
;

import
 java
.
sql
.
PreparedStatement
;

import
 java
.
sql
.
ResultSet
;

import
 javax
.
naming
.
Context
;

import
 javax
.
naming
.
InitialContext
;

import
 javax
.
naming
.
NamingException
;

import
 javax
.
sql
.
DataSource
;

/**
 *
 * 
@author
 christoforos
 */

public
 
class
 
Accessor
 
{

    
public
 
Account
 getAccount
(
int
 acNum
,
 
int
 pin
)
 
{

        
try
{

            
Connection
 cn 
=
 getBankDB
().
getConnection
();

            
String
 sql 
=
 
“SELECT * FROM account WHERE aNum = ? and pin = ?”
;

            
PreparedStatement
 pst 
=
 cn
.
prepareStatement
(
sql
);

            pst
.
setInt
(
1
,
 acNum
);

            pst
.
setInt
(
2
,
 pin
);

            
ResultSet
 rs 
=
 pst
.
executeQuery
();

            
if
(
rs
.
next
())
 
{

                
Account
 acc 
=
 
new
 
Account
();

                acc
.
setAcNum
(
acNum
);

                acc
.
setPin
(
pin
);

                acc
.
setBalance
(
rs
.
getInt
(
“balance”
));

                acc
.
setId
(
rs
.
getInt
(
“aid”
));

                acc
.
setLimit
(
rs
.
getInt
(
“limit”
));

                
return
 acc
;

            
}

        
}

        
catch
(
Exception
 e
)
 
{}

        
return
 
null
;

    
}

    
public
 
boolean
 checkBalance
(
int
 amount
,
 
Account
 me
)
 
{

        
if
(
amount 
>
 me
.
getBalance
()
 
+
 me
.
getLimit
())
 
return
 
false
;

        
return
 
true
;

    
}

    
public
 
void
 makeWithdrawal
(
int
 amount
,
 
int
 acid
)
 
{

        
try
{

            
Connection
 cn 
=
 getBankDB
().
getConnection
();

            
try
{

                cn
.
setAutoCommit
(
false
);

                
String
 sql 
=
 
“UPDATE account SET balance = balance – ? WHERE aid = ?”
;

                
PreparedStatement
 pst 
=
 cn
.
prepareStatement
(
sql
);

                pst
.
setInt
(
1
,
 amount
);

                pst
.
setInt
(
2
,
 acid
);

                pst
.
executeUpdate
();

                sql 
=
 
“INSERT INTO log (account, amount) VALUES (?, ?)”
;

                pst 
=
 cn
.
prepareStatement
(
sql
);

                pst
.
setInt
(
1
,
 acid
);

                pst
.
setInt
(
2
,
 amount
);

                pst
.
executeUpdate
();

                cn
.
commit
();

            
}

            
catch
(
Exception
 ex
)
 
{

                cn
.
rollback
();

            
}

        
}

        
catch
(
Exception
 e
)
 
{

        
}

    
}

    
private
 
DataSource
 getBankDB
()
 
throws
 
NamingException
 
{

        
Context
 c 
=
 
new
 
InitialContext
();

        
return
 
(
DataSource
)
 c
.
lookup
(
“java:comp/env/bankDB”
);

    
}

}

transEx/src/java/pack/Account.java
transEx/src/java/pack/Account.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package
 pack
;

/**
 *
 * 
@author
 christoforos
 */

public
 
class
 
Account
 
{

    
private
 
int
 id
;

    
private
 
int
 acNum
;

    
private
 
int
 pin
;

    
private
 
int
 balance
;

    
private
 
int
 limit
;

    
/**
     * 
@return
 the id
     */

    
public
 
int
 getId
()
 
{

        
return
 id
;

    
}

    
/**
     * 
@param
 id the id to set
     */

    
public
 
void
 setId
(
int
 id
)
 
{

        
this
.
id 
=
 id
;

    
}

    
/**
     * 
@return
 the acNum
     */

    
public
 
int
 getAcNum
()
 
{

        
return
 acNum
;

    
}

    
/**
     * 
@param
 acNum the acNum to set
     */

    
public
 
void
 setAcNum
(
int
 acNum
)
 
{

        
this
.
acNum 
=
 acNum
;

    
}

    
/**
     * 
@return
 the pin
     */

    
public
 
int
 getPin
()
 
{

        
return
 pin
;

    
}

    
/**
     * 
@param
 pin the pin to set
     */

    
public
 
void
 setPin
(
int
 pin
)
 
{

        
this
.
pin 
=
 pin
;

    
}

    
/**
     * 
@return
 the balance
     */

    
public
 
int
 getBalance
()
 
{

        
return
 balance
;

    
}

    
/**
     * 
@param
 balance the balance to set
     */

    
public
 
void
 setBalance
(
int
 balance
)
 
{

        
this
.
balance 
=
 balance
;

    
}

    
/**
     * 
@return
 the limit
     */

    
public
 
int
 getLimit
()
 
{

        
return
 limit
;

    
}

    
/**
     * 
@param
 limit the limit to set
     */

    
public
 
void
 setLimit
(
int
 limit
)
 
{

        
this
.
limit 
=
 limit
;

    
}

}

transEx/web/checkLogin.jsp
<%-- read the accid and the pin from the request use the function in the bean to see if it is ok if ok save my account in the session go to the withraw page else go to login with an error message --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import = "pack.Account" %>

<%! pack.Accessor oracle123 = new pack.Accessor(); %>
<% String acNum = request.getParameter("acnum"); String pin = request.getParameter("pin"); Account me = oracle.getAccount(Integer.parseInt(acNum), Integer.parseInt(pin) ); if(me != null) { session.setAttribute("me", me); response.sendRedirect("withdrawal.jsp"); } else { %>



<% } %>

transEx/web/doWithdraw.jsp
<%-- check if balance is sufficient if it is do transaction else show error --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import = "pack.Account" %>


<% String amount = request.getParameter("amount"); Account me = (Account) session.getAttribute("me"); if(oracle.checkBalance(Integer.parseInt(amount), me)) { oracle.makeWithdrawal(Integer.parseInt(amount), me.getId()); %>



<% } else { %>



<% } %>

transEx/web/login.jsp
<%-- Document : index Created on : Apr 6, 2011, 3:29:28 PM Author : christoforos --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page

Put your credentials

Account Number
Pin

<% String msg = request.getParameter("msg"); if(msg != null) out.println(msg); %>


transEx/web/META-INF/context.xml

transEx/web/WEB-INF/web.xml

30

index.jsp

jdbc:mysql://localhost:3306/bank
bankDB
javax.sql.DataSource
Container
Shareable

transEx/web/withdrawal.jsp
<%-- Document : withdrawal Created on : Apr 6, 2011, 3:30:14 PM Author : christoforos --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>




JSP Page

How much to withdraw



<% String msg = request.getParameter("msg"); if(msg != null) out.println(msg); %>

Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER