我已经创建了注册表。而且我不知道为什么现在它不再起作用了。 现在,我收到404错误:
类型状态报告
消息/ HotelReservation / Registration
说明原始服务器未找到当前表示 目标资源或不愿意透露其存在。
这是我的
Registration.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hotel;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author OOPs
*/
public class Registration extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String s1 = request.getParameter("ename");
String s2 = request.getParameter("nname");
String s3 = request.getParameter("pname");
String s4 = request.getParameter("usid");
String s5 = request.getParameter("gm");
PrintWriter out = response.getWriter();
try {
/* TODO output your page here. You may use following sample code.
out.println(s1);
out.println(s2);
out.println(s3);
out.println(s4);
out.println(s5);*/
// out.println(s1);
//concetivity...............
Class.forName("com.mysql.jdbc.Driver");
out.println("driver loaded");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/HotelReservation","root" ,"123456789");
out.println("Connect");
Statement st = con.createStatement();
out.println("conncetion successfull");
st.executeUpdate("insert into register (email,name,pass) values ('"+s1+"','"+s2+"','"+s3+"')");
out.println("<h1> Register sucsefulltttt </h1>");
response.sendRedirect("thankyou.jsp");
}catch(Exception e){
out.println("nahiiiiiiiiiiiii" +e);
}
finally {
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
这是我的
registration.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration</title>
<style>
@import url( css/default.css);
</style>
</head>
<body>
<div id="container">
<div id="nav">
<a href="home.html">Home</a>
<a href="prenotazione.jsp">Prenotazione</a>
<a href="Room.html">Camere</a>
<a href="login.jsp">Login</a>
<a href="registration.jsp">Registrazione</a>
</div>
<script>
function validate()
{
if(document.getElementById("ename").value=="")
{
alert("blank");
return false;
}
return true;
}
</script>
<h2>Registrazione</h2>
<form action="Registration" method="post" onsubmit="return validate();">
<div class="gender">
<label id="icon" for="name"><i class="icon-envelope "></i></label>
<input type="text" name="ename" id="ename" placeholder="Email" required/>
<br>
<br>
<label id="icon" for="name"><i class="icon-user"></i></label>
<input type="text" name="nname" id="nname" placeholder="Name" required/>
<br>
<br>
<label id="icon" for="name"><i class="icon-shield"></i></label>
<input type="password" name="pname" id="pname" placeholder="Password" required/>
<br>
<input class="button" type="submit" value="Sign UP" name="b1"> </input>
<input class="button" type=button onClick="location.href='login.jsp'" value="Login" name="b" > </input>
</form>
<div id="footer">
<h4>Hotel Reservation </h4>
Viale Marco Polo, 81 Roma
tel: +39 01 0000000 | info@hotelreservation.it
P.IVA 000000001
</div>
</div>
</body>
</html>
您认为我该如何解决?谢谢
编辑: 这是我的:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Hotelbooking</display-name>
<servlet>
<servlet-name>Hotelbooking</servlet-name>
<servlet-class>hotel.Hotelbooking</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hotelbooking</servlet-name>
<url-pattern>/hotelbooking</url-pattern>
</servlet-mapping>
<display-name>Login</display-name>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>hotel.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<display-name>Logout</display-name>
<servlet>
<servlet-name>Logout</servlet-name>
<servlet-class>hotel.Logout</servlet-class>
</servlet>
<display-name>Registration</display-name>
<servlet>
<servlet-name>Registration</servlet-name>
<servlet-class>hotel.Registration</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/registration</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>home.html</welcome-file>
</welcome-file-list>
</web-app>
HTTP状态404 –找不到
类型状态报告
消息/ HotelReservation / Registration
说明原始服务器未找到当前表示 目标资源或不愿意透露其存在。
答案 0 :(得分:0)
编写您的doGet
方法,以便在registration.jsp
处转发
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.getRequestDispatcher("/registration.jsp").forward(request, response);
}
错误消息图中的另一件事,显示/HotelReservation/Registration
但在web.xml文件中,servlet映射为/registration
。所以点击正确的网址