0

im currently doing my final year project about lost and found system using java and oracle database (MVC).

my problem is after I submit the form the page will show this the message says it redirect to the FoundRegisterController

it supposedly register the found item. but it did not. how can I solve this problem? Below are the codes for the jsp, controller and DAO

this is registerFoundItem.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!doctype html>
<html class="no-js" lang="en">

<head>
<jsp:include page="css.jsp"></jsp:include>
</head>

<body>
    <jsp:include page="header.jsp" />

    <!-- tabs & register form Start -->
    <div class="basic-form-area mg-b-15">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="sparkline8-list mt-b-30">
                        <div class="sparkline8-graph">
                            <div class="basic-login-form-ad">
                                <div class="row">
                                    <div class="col-lg12 col-md-12 col-sm-12 col-xs-12">
                                        <h2>
                                            <center>Register New Found Item</center>
                                        </h2>
                                        <br> <br>
                                    </div>
                                </div>
                                <%
                                    String userEmail = (String) session.getAttribute("currentSessionUser");
                                %>
                                <%
                                    String userNoPhone = (String) session.getAttribute("currentSessionUserNoPhone");
                                %>
                                <%
                                    String userName = (String) session.getAttribute("currentSessionUserName");
                                %>
                                <div class="row">
                                    <form action="FoundRegisterController" method="post">
                                        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
                                            <div class="basic-login-inner">
                                                <h4>Reporter Details:</h4>

                                                <div class="form-group-inner">
                                                    <label>Post by:</label> <input type="text"
                                                        class="form-control" name="UserName"
                                                        value="<c:out value="<%=userName%>" />" disabled />
                                                </div>
                                                <div class="form-group-inner">
                                                    <label>Contact Number: </label><input type="text"
                                                        class="form-control" name="UserNoPhone"
                                                        value="<c:out value="<%=userNoPhone%>" />" disabled />
                                                </div>
                                                <div class="form-group-inner">
                                                    <label>Email: </label><input type="text"
                                                        class="form-control" name="UserNoPhone"
                                                        value="<c:out value="<%=userEmail%>" />" disabled />
                                                </div>
                                                <br>
                                            </div>
                                        </div>

                                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
                                        <h4>Found Item Details :</h4></div>
                                        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
                                            <label>Date:</label> <input class="form-control"
                                                name="FItemDate" type="date" required />
                                        </div>
                                        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
                                            <label>Time:</label> <input class="form-control"
                                                name="FItemTime" type="time"
                                                required />
                                        </div>
                                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
                                            <div class="form-group-inner">
                                                <label><br>Found Item Name:</label> <input type="text"
                                                    class="form-control" name="FItemName"
                                                    placeholder="eg: iPhone 8 Plus | ASUS | GoPro 5 Black"
                                                    title="Please enter the valid name. Do not use shortform"
                                                    required />
                                            </div>
                                            <div class="form-group-inner">
                                                <label>Found Item Category:</label>
                                                <div class="form-select-list">
                                                    <select class="form-control custom-select-value"
                                                        name="account" name="FItemCategory">
                                                        <option disabled selected value>-- Select
                                                            Category --</option>
                                                        <option value="FoundItem">Mobile Phone</option>
                                                        <option value="FoundItem">Laptop/Notebook</option>
                                                        <option value="FoundItem">Keys</option>
                                                        <option value="FoundItem">Cards</option>
                                                        <option value="FoundItem">UiTM Matrics Card</option>
                                                        <option value="FoundItem">Other..</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group-inner">
                                                <label>Location:</label> <input class="form-control"
                                                    name="FItemLocation"
                                                    placeholder="eg: Blok Kuliah 17 | JMK 8 | Cafe Kuliah"
                                                    title="Please enter the valid name. Do not use shortform"
                                                    required />
                                            </div>
                                            <div class="form-group-inner">
                                                <label>Description: </label>
                                                <div class="form-group edit-ta-resize res-mg-t-15">
                                                    <textarea name="description" name="FItemDescription" placeholder="eg: Barang dijumpai di bawah meja/atas lantai/depan pintu/atas meja pensyarah/etc.. anggaran waktu dijumpai 2ptg-6ptg"></textarea>
                                                    </div>
                                            </div>

                                            <div class="login-btn-inner">
                                                <div class="inline-remember-me">
                                                    <button
                                                        class="btn btn-sm btn-primary pull-right login-submit-cs"
                                                        type="submit" name="action">
                                                        <b>Register</b>
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <br>
    </div>
    <!-- tabs & Register form End-->


    <!-- JS -->
    <jsp:include page="js.jsp"></jsp:include>

</body>

</html>

this is my FoundRegisterController.java

package lofo.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.NoSuchAlgorithmException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lofo.dao.foundDAO;
import lofo.model.FoundItemBean;

/**
 * Servlet implementation class RegisterController
 */
@WebServlet("/FoundRegisterController")
public class FoundRegisterController extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private String VIEW ="/lofo/viewFound.jsp";
    private foundDAO dao;
    String forward=""; 
    String action="";
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FoundRegisterController() {
        super();
        // TODO Auto-generated constructor stub
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String action = request.getParameter("action");

        if(action.equalsIgnoreCase("viewFound")) {
            forward = VIEW;
            String UserEmail = request.getParameter("UserEmail");
            FoundItemBean found = dao.getUserByEmail(UserEmail);
            request.setAttribute("found", found);
        }

        RequestDispatcher view = request.getRequestDispatcher(forward);
        view.forward(request, response);
    }




    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        action = request.getParameter("action");
        try {

            String FItemID = request.getParameter("FItemID");
            String UserEmail = request.getParameter("UserEmail");
            String FItemName = request.getParameter("FItemName");
            String FItemCategory = request.getParameter("FItemCategory");
            String FItemDate = request.getParameter("FItemDate");
            String FItemTime = request.getParameter("FItemTime");
            String FItemLocation = request.getParameter("FItemLocation");
            String FItemDescription = request.getParameter("FItemDescription");

            FoundItemBean found = new FoundItemBean();

            found.setFItemID(FItemID);
            found.setUserEmail(UserEmail);
            found.setFItemName(FItemName);
            found.setFItemCategory(FItemCategory);
            found.setFItemDate(FItemDate);
            found.setFItemTime(FItemTime);
            found.setFItemLocation(FItemLocation);
            found.setFItemDescription(FItemDescription);


            dao = new foundDAO();
            found = foundDAO.getUser(found);

            try {
                dao.FoundAdd(found);
            } catch (NoSuchAlgorithmException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            response.setContentType("text/html");
            PrintWriter pw = response.getWriter();
            pw.println("<script>");
            pw.println("alert('The item post has been created');");
            pw.println("window.location.href='FoundController?action=listFoundItem';");
            pw.println("</script>");
        }

        catch (Throwable ex) {
            System.out.println(ex);
        }
    }
}

this is my FoundController.java

package lofo.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.security.NoSuchAlgorithmException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import lofo.dao.foundDAO;
import lofo.model.FoundItemBean;

/**
 * Servlet implementation class UserController
 */
@WebServlet("/FoundController")
public class FoundController extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private String VIEW ="viewFound.jsp";
    private String VIEWALL ="listFoundItem.jsp";
    private static String UPDATE = "updateFound.jsp";
    private static String DELETE = "deleteFound.jsp";
    private static String SEARCH = "registerFoundItem.jsp";

    String forward;
    private foundDAO dao;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FoundController() {
        super();
        dao = new foundDAO();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String action = request.getParameter("action");

        if(action.equalsIgnoreCase("viewFound")) {
            forward = VIEW;
            String UserEmail = request.getParameter("UserEmail");
            FoundItemBean found = foundDAO.getUserByEmail(UserEmail);
            List<FoundItemBean> founds = foundDAO.getAllFound();
            request.setAttribute("founds", founds );
            request.setAttribute("found", found);
        }
        else if (action.equalsIgnoreCase("listFoundItem")) {
            forward = VIEWALL;
            request.setAttribute("founds", foundDAO.getAllFound()); 

        }
        else if (action.equalsIgnoreCase("updateFound")){
            forward = UPDATE;
            String UserEmail = request.getParameter("UserEmail");
            FoundItemBean found = foundDAO.getUserByEmail(UserEmail);
            List<FoundItemBean> founds = foundDAO.getAllFound();
            request.setAttribute("founds", founds);
            request.setAttribute("found", found);
        }
        else if (action.equalsIgnoreCase("search")){
            forward = SEARCH;
            List<FoundItemBean> found = foundDAO.getAllFound();
            request.setAttribute("founds", found);
        }
        else if (action.equalsIgnoreCase("deleteFound")){
            forward = DELETE;
            String UserEmail = request.getParameter("UserEmail");
            FoundItemBean found = foundDAO.getUserByEmail(UserEmail);
            request.setAttribute("found", found);
        }
        RequestDispatcher view = request.getRequestDispatcher(forward);
        view.forward(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        String action = request.getParameter("action");
        if(action.equalsIgnoreCase("Submit")) {

            String UserEmail = request.getParameter("UserEmail");
            String FItemName = request.getParameter("FItemName");
            String FItemCategory = request.getParameter("FItemCategory");
            String FItemDate = request.getParameter("FItemDate");
            String FItemTime = request.getParameter("FItemTime");
            String FItemLocation = request.getParameter("FItemLocation");
            String FItemDescription = request.getParameter("FItemDescription");

            FoundItemBean found = new FoundItemBean();

            found.setUserEmail(UserEmail);
            found.setFItemName(FItemName);
            found.setFItemCategory(FItemCategory);
            found.setFItemDate(FItemDate);
            found.setFItemTime(FItemTime);
            found.setFItemLocation(FItemLocation);
            found.setFItemDescription(FItemDescription);

            dao = new foundDAO();
            try {
                dao.updateFound(found);
                /*forward = VIEW;
            user = UserDAO.getUserByEmail(UserEmail);
            request.setAttribute("user", user); */
                response.setContentType("text/html");
                PrintWriter pw = response.getWriter();
                pw.println("<script>");
                pw.println("alert('The account is updated');");
                pw.println("window.location.href='/lofo/FoundController?action=viewFound&UserEmail="+ UserEmail +"';");
                pw.println("</script>");

            } catch (NoSuchAlgorithmException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //}
            //else if(action.equalsIgnoreCase("Delete")) {
            //String UserEmail = request.getParameter("UserEmail");
            // = new foundDAO();
            //dao.deleteUser(UserEmail);
            //response.setContentType("text/html");
            //PrintWriter pw = response.getWriter();
            //pw.println("<script>");
            //pw.println("alert('The account has been deleted');");
            //pw.println("window.location.href='/Inventory/UserController?action=listAll';");
            //pw.println("</script>");
            //}
        }
    }
}

this is my foundDAO.java

package lofo.dao;
import java.sql.Statement;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import lofo.model.FoundItemBean;
import lofo.model.UsersBean;
import lofo.connection.ConnectionManager;

public class foundDAO {
    static Connection currentCon = null;
    static ResultSet rs = null;
    static PreparedStatement ps = null;
    static Statement stmt = null;
    static String FItemID, UserEmail, FItemName, FItemCategory, FItemDate, FItemTime, FItemLocation, FItemDescription;

     public static FoundItemBean getUser(FoundItemBean bean)  {

         UserEmail = bean.getUserEmail();

         String searchQuery = "select * from founditem where useremail='" + UserEmail + "'";

         try {
             currentCon = ConnectionManager.getConnection();
             stmt = currentCon.createStatement();
             rs = stmt.executeQuery(searchQuery);
             boolean more = rs.next();

             // if user exists set the isValid variable to true
             if (more) {
                String UserEmail = rs.getString("UserEmail");

                 bean.setUserEmail(UserEmail);
                 bean.setValid(true);
                }

             else if (!more) {
                System.out.println("Sorry");
                bean.setValid(false);
             }

         }

         catch (Exception ex) {
             System.out.println("Log In failed: An Exception has occurred! " + ex);
         }

         finally {
             if (rs != null) {
                 try {
                     rs.close();
                 } catch (Exception e) {
                 }
                 rs = null;
             }

             if (stmt != null) {
                 try {
                     stmt.close();
                 } catch (Exception e) {
                 }
                 stmt = null;
             }

             if (currentCon != null) {
                 try {
                     currentCon.close();
                 } catch (Exception e) {
                 }

                 currentCon = null;
             }
         }

         return bean;
     }

    //get user by email
    public static FoundItemBean getUserByEmail(String UserEmail) {
        FoundItemBean found = new FoundItemBean();
        try {
            currentCon = ConnectionManager.getConnection();
            ps=currentCon.prepareStatement("select * from founditem where useremail=?");

            ps.setString(1, UserEmail);

            ResultSet rs = ps.executeQuery();

            if (rs.next()) {

                found.setFItemID(rs.getString("FItemID"));
                found.setUserEmail(rs.getString("UserEmail"));
                found.setFItemName(rs.getString("FItemName"));
                found.setFItemCategory(rs.getString("FItemCategory"));
                found.setFItemDate(rs.getString("FItemDate"));
                found.setFItemTime(rs.getString("FItemTime"));
                found.setFItemLocation(rs.getString("FItemLocation"));
                found.setFItemDescription(rs.getString("FItemDescription"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return found;
    }

    //create Found Item
    public void FoundAdd (FoundItemBean bean) throws NoSuchAlgorithmException {


        FItemID = bean.getFItemID();
        UserEmail = bean.getUserEmail();
        FItemName = bean.getFItemName();
        FItemCategory = bean.getFItemCategory();
        FItemDate = bean.getFItemDate();
        FItemTime = bean.getFItemTime();
        FItemLocation = bean.getFItemLocation();
        FItemDescription = bean.getFItemDescription();

        try {
            currentCon = ConnectionManager.getConnection(); 
            ps=currentCon.prepareStatement("insert into founditem(FItemID, UserEmail, FItemName, FItemCategory, FItemDate, FItemTime, FItemLocation, FItemDescription) values (FOUNDITEM_SEQ.nextval,?,?,?,?,?,?,?)");

            ps.setString(1,UserEmail);
            ps.setString(2,FItemName);
            ps.setString(3,FItemCategory);
            ps.setString(4,FItemDate);
            ps.setString(5,FItemTime);
            ps.setString(6,FItemLocation);
            ps.setString(7,FItemDescription);
            ps.executeUpdate();

            System.out.println("Your FItemName is " + FItemName);

        }

        catch (Exception ex) {
            System.out.println("failed: An Exception has occured!" + ex);
        }

        finally {
            if (ps != null) {
                try {
                    ps.close();
                } catch (Exception e) {
                }
                ps = null;
            }

            if (currentCon != null) {
                try {
                    currentCon.close();
                } catch (Exception e) {
                }
                currentCon = null;

            }
        }
    }

    //update account
    public void updateFound(FoundItemBean bean) throws NoSuchAlgorithmException {

        FItemName = bean.getFItemName();
        FItemCategory = bean.getFItemCategory();
        FItemDate = bean.getFItemDate();
        FItemTime = bean.getFItemTime();
        FItemLocation = bean.getFItemLocation();
        FItemDescription = bean.getFItemDescription();

        String searchQuery = "";


        searchQuery = "UPDATE founditem SET FItemName ='"+ FItemName +"', FItemCategory='" + FItemCategory + "', FItemDate='" + FItemDate + "', FItemTime='" + FItemTime + "', FItemLocation='" + FItemLocation + "', FItemDescription='" + FItemDescription + "' WHERE UserEmail= '" + UserEmail + "'";       
        System.out.println(searchQuery);


        try {

            currentCon = ConnectionManager.getConnection();
            stmt = currentCon.createStatement();
            stmt.executeUpdate(searchQuery);
            System.out.println(searchQuery);

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    //getAllFound for list table
    public static List<FoundItemBean> getAllFound() {
        List<FoundItemBean> founds = new ArrayList<FoundItemBean>();

        try {
            currentCon = ConnectionManager.getConnection();
            stmt = currentCon.createStatement();

            String q = "select * from founditem";
            ResultSet rs = stmt.executeQuery(q);

            while (rs.next()) {
                FoundItemBean found = new FoundItemBean();

                found.setUserEmail(rs.getString("UserEmail"));
                found.setFItemName(rs.getString("FItemName"));
                found.setFItemCategory(rs.getString("FItemCategory"));
                found.setFItemDate(rs.getString("FItemDate"));
                found.setFItemTime(rs.getString("FItemTime"));
                found.setFItemLocation(rs.getString("FItemLocation"));
                found.setFItemDescription(rs.getString("FItemDescription"));
                founds.add(found);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return founds;
    }
}
Sue A.
  • 29
  • 6

1 Answers1

0

The error message shown in the attached picture is -

"The origin server did not find a current representation for the target resource..."

This error is usually not due to a problem in the code. This error is caused due to an issue with the IDE (Common with Eclipse), or due to the way the application is deployed on the Web server.

Here is a workaround for this problem:

  1. Take a backup of the project files.
  2. Delete the project from eclipse.
  3. Make sure that the character encoding is set to 'utf-8' in all the html template files**
<html lang="en">
    <head>
        <meta charset="utf-8"/>
    </head>
  1. Restart eclipse.
  2. Do a fresh import of the project into eclipse.

  3. Verify the web.xml file for the correct mapping of servlets

More help:

https://www.codejava.net/java-ee/servlet/solved-tomcat-error-http-status-404-not-found

The origin server did not find a current representation for the target resource or is not ... error when running jsp page

Tomcat 404 error: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists

Gopinath
  • 4,066
  • 1
  • 14
  • 16
  • 1
    hello sir, i have try your suggestion and it is working ! thank you very much for your help :) – Sue A. Apr 13 '20 at 19:56