Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Description: you are required to build a simple web application using J2EE, spri

ID: 664127 • Letter: D

Question

Description:
   
you
are
required
to
build
a
simple
web
application
using
J2EE,
spring/struts
  framework
  with
  a
  database.

Requirements:
  

The
  application
  needs
  to
  be
  developed
  using
  Java
  language
  (J2EE)
  on
  Eclipse
  IDE.

The
Web
application
framework
that
you
would
use
should
Spring
and
or
Struts2
on
Tomcat
  webserver.
  

The
relational
database
should
be
stored
in
an
RDBMS
of
your
choice
(MySQL,
MongoDB,
  Hibernate,
  Oracle..)
  

Deliverables:

Java
  source
  code
  (all
  the
  classes
  /
  jar
  files)
  

A
detailed
step
by
step
reports
on
rebuilding
and
running
the
application
(include
all
  your
  references).
  The
  report
  should
  explain
  every
  component
  in
  your
  application.
   
  

Both
  deliverables
  should
  be
  submitted
  on
  blackboard
  on
  a
  zip
  file
  

A
two-­page
report
on
how
the
MVC
Design
Pattern
was
used
in
your
application.
  
Explain
in
your
own
words
the
struts,
spring
framework
that
you
used
in
your
homework.
  

Research
  Readings
  and
  learning
  outcomes:
  

• MVC
  Design
  Pattern
  

• J2EE
   
  

• MVC
  Model
  

• Spring
  framework
   
  

• Struts
  framework
  

• Relational
  Databases
  (or
  NoSQL)
  

• Tomcat
  webserver
  

More
  Details:
   
  Login
  Page
  

Login
Page
should
be
a
simple
page
with
username
and
password,
login
and
reset
buttons.
  
The
login
and
password
must
be
saved
and
retrieved
  from
  a
  database.
   
  Choice
  Page
  

Once
  the
  user
  logs
  in
  successfully,
  the
  Choice
  page
  shows
  up.
  The
  

Choice
page
displays
the
user
name
and
has
two
buttons:
  
(1)
Write
New
  Text,
  (2)
  View
  All
  Texts.
   

Text
  Page
  

Once
the
user
is
logged
in
and
clicks
on
(1)
Write
New
Text,
you
will
need
to
redirect
the
user
to
the
Text
page
where
they
can
write
some
text
(a
paragraph
or
multiple)
in
text
field.
The
page
should
have
a
save
  button
  that
  will
  save
  the
  text
  in
  a
  database.
   
  

View
  Texts
  Page
  

From
the
login
page
if
the
user
clicks
(2)
View
All
Texts.
Then
this
page
  will
  display
  all
  the
  texts
  the
  user
  has
  been
  submitted.
   
  

Bonus
  –
  Registration
  Page
  

This
is
an
optional
bonus.
Allow
your
application
to
have
multiple
users
  to
  register
  via
  a
  registration
  page.
   
  

Explanation / Answer

loginForm.html

<html>
    <head>
        <title>Login form</title>
    </head>
    <body>
        <h1>Login</h1>
            <h2>Signup Details</h2>
            <form action="checkMyLogin.jsp" method="post">
            <br/>Username:<input type="text" id="username" name="username">
            <br/>Password:<input type="password" id="password" name="password">
            <br/><input type="submit" value="Submit">
            </form>
    </body>
</html>

checkMyLogin.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<html>
    <head>
        <title>check my login</title>
    </head>
    <body>
        <%
        String username=request.getParameter("username");
        String password=request.getParameter("password");
        try {
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             conn = DriverManager.getConnection("jdbc:odbc:Users","username","password");
             stmt = conn.createStatement();
             String query = "SELECT Users.username,Users.password FROM Users WHERE usersname='"+username+"';";
             ResultSet rs = stmt.executeQuery(query);
             while (rs.next()) {
           String user=rs.getString("user");
               String pass=rs.getString("password");
             }
       } catch (SQLException e) {
             out.println("An error occured while retrieving " + "all users" + e.toString());
       } catch (ClassNotFoundException e) {
             throw (new ServletException(e.toString()));
       } finally {
             try {
               if (stmt != null) {
                     stmt.close();
               }
               if (conn != null) {
                   conn.close();
               }
             } catch (SQLException ex) {}
       }
        if((username.equals(user) && password.equals(pass)))
            {
               session.setAttribute("username",username);
               response.sendRedirect("makeAChoice.jsp");
            }
        else
            response.sendRedirect("Error.jsp");
        %>
    </body>
</html>

makeAChoice.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
    <head>
        <title>make a choice</title>
    </head>
    <body>
        Welcome <%=session.getAttribute("username")%>
   <a href="writenewtext.jsp">Write New Text</a>
   <a href="viewalltext.jsp">View All Texts</a>
    </body>
</html>

writenewtext.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
    <head>
        <title>write new text</title>
    </head>
    <body>
   <form action="writedata.jsp" method="post">
       <input type="text" id="data" name="data" />
       <input type="submit" value="Submit" />
   </form>
    </body>
</html>


writedata.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@page import="java.sql.*" %>

<html>
    <head>
        <title>write data</title>
    </head>
    <body>
        <% Connection connection = null;
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            connection = DriverManager.getConnection("jdbc:odbc:data", "username", "password");

            Statement statement = connection.createStatement();

            String command = "INSERT INTO TEXTS (data) VALUES ('"+request.getParameter("data")+"');";
            statement.executeUpdate(command);
   %>
    </body>
</html>

viewalltext.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@page import="java.sql.*" %>

<html>
    <head>
        <title>view all data</title>
    </head>
    <body>
   <TABLE BORDER="1">
                <TR>
                    <TH>Id</TH>
                    <TH>Data</TH>
                </TR>
        <% try{
        Connection connection = null;
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            connection = DriverManager.getConnection("jdbc:odbc:data", "username", "password");
        stmt = conn.createStatement();
              String query = "SELECT TEXTS.id,TEXTS.data FROM TEXTS";
              ResultSet rs = stmt.executeQuery(query);
              while (rs.next()) {
               String id=rs.getString("id");
                String data=rs.getString("data");
   %>
       <tr><td><%=id%></td>
       <td><%=data%></td></tr>
   <%
              }
           } catch (SQLException e) {
                     out.println("An error occured while retrieving " + "all users" + e.toString());
           } catch (ClassNotFoundException e) {
                     throw (new ServletException(e.toString()));
           } finally {
                 try {
                   if (stmt != null) {
                             stmt.close();
                   }
                   if (conn != null) {
                           conn.close();
                   }
                 } catch (SQLException ex) {}
            }
   %>
   </TABLE>
    </body>
</html>