- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在做我的最后一年项目,关于使用 Java 和 Oracle 数据库 (MVC) 的失物招领系统。
我的问题是在我提交表单后,页面将显示此 the message says it redirect to the FoundRegisterController
它应该注册找到的项目。但事实并非如此。我怎么解决这个问题?下面是jsp、 Controller 和DAO的代码
这是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>
这是我的 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);
}
}
}
这是我的 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>");
//}
}
}
}
这是我的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;
}
}
最佳答案
附图中显示的错误消息是 -
“源服务器未找到目标资源的当前表示...”
此错误通常不是由于代码中的问题造成的。此错误是由于 IDE 问题(常见于 Eclipse)或由于应用程序在 Web 服务器上部署的方式引起的。
以下是此问题的解决方法:
<html lang="en">
<head>
<meta charset="utf-8"/>
</head>
将项目重新导入到 Eclipse 中。
验证 web.xml 文件是否正确映射 servlet
更多帮助:
https://www.codejava.net/java-ee/servlet/solved-tomcat-error-http-status-404-not-found
关于java - 按下提交按钮后显示 404 错误并带有 Controller 消息如何解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61195053/
假设我有一个带有隐藏提交按钮的表单,我在其中输入值,然后我点击一个按钮,就会出现带有确认消息和确认按钮的对话框。当我单击“确认”按钮时,我还单击了表单中隐藏的提交按钮。这可能吗?我如何在 JQuery
我们正在学习 Git 并使用 GitHub 作为我们的托管站点。 我们都 fork upstream repo 并 PR 我们的提交到 upstream 以获取我们的更改。 我们正在努力学习如何压缩我
我只需要一些关于这段代码的帮助。 var prv3; var markIt3 = function(e) { if (prv3 === this && this.checked) { th
如果 1 个表单使用“GET”方法而另一个使用“POST”方法,我如何提交位于同一页面上的 2 个表单。每个表单都有相同的操作并转到相同的下一页。需要帮忙。感谢大家的帮助。 我怎样才能得到下面这两个使
您好,我的表单中有以下脚本 function pdf() { var frm = document.getElementById("form1"); frm.action = "http://www.
我有一个 iOS 胖静态库(iphoneos 和 iphonesimulator),如果我在应用程序提交期间使用它,它会因为二进制文件包含 iphonesimulator 代码而失败吗? 最佳答案 我
我似乎有一个卡住的 git repo。它卡在所有基本的添加、提交命令上,git push 返回所有内容为最新的。 从其他帖子我已经完成了 git gc 和 git fsck/ 我认为基本的调试步骤是
我正在尝试发送由 jquery 创建的表单。该表单附加到一个 div 中,下面的变量“data”是使用 php 创建的,我将只发布最重要的 js 代码。 我尝试了很多带有和不带有“on()”的操作,但
我面临一个简单的问题,但不知道如何解决。我正在使用 twitter bootstrap 的标签。选项卡有效,但每个选项卡中的表单不提交。表单在没有选项卡的情况下提交。 以下是我用于标签的链接
我的计算机上有 140 个 git 存储库,每周我可以处理其中 10-15 个。有没有办法知道是否忘记提交/推送我的一个项目? 这些存储库都位于同一位置:“C:/Projects”。 输出类似于 C:
我对 javascript 完全陌生,目前正在开发我的第一个函数。我有这 2 个文本输入区域,可以在其中输入他的姓名和级别。 Nom: Niveau (1 á 6): 提交后,
我安装了最新的 Docker CS,得到了 LAMP image来自 Docker 集线器。我正在尝试在其中创建一个数据库并使用保存在其中的数据库制作一个新图像。 启动容器:docker run --
我有这个 jQuery 简单代码: 由于某种原因,submit() 无法正常工作(我的表单在单击 old_thumb 按钮后未提交。有人可以帮助我吗? 这里是 html 的一部分(它很长
如何获得 input type="submit"onclick 事件来触发 commitfunds.valdiate?我不能使用类或 ID。它必须是一个 onclick 事件。 这是代码: row A
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
来自 this earlier thread我以为我知道可以使用 javascript submit() 命令通过 POST 方法发送表单数据。但我无法让它工作。这个演示在目的方面没有明显的意义,但请
在 mysql 重新启动时提交 XA 待处理事务时,出现以下错误。请帮助我解决这个错误。 mysql> XA RECOVER CONVERT XID; +----------+------------
我有一个带有 的表单. 如果启用了 Javascript,我将删除此 submit -输入字段$('#no-js-submit').remove();并添加“fire-ajax”按钮 $('Fire
我希望在页面加载后提交此表单,并且我使用了以下代码来完成此操作。问题是页面不断重新加载并停留在该循环中。 HTML Select Genre
我们有一个表单,其中有几个单独的提交按钮,它们执行不同的操作。问题是我有几个具有以下 HTML 的按钮: 现在您无法使用标准的 find_control 函数按值定位元素。所以我写了一个谓词函数来
我是一名优秀的程序员,十分优秀!