gpt4 book ai didi

Eclipse Java EE 和 Tomcat 6 : Error 404 requested resource not available

转载 作者:行者123 更新时间:2023-11-28 23:38:22 25 4
gpt4 key购买 nike

我遇到了错误

 HTTP Status 404 - /ot/LoginValidationServlet

--------------------------------------------------------------------------------

type Status report

message /ot/LoginValidationServlet

description The requested resource is not available.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.36

每当我运行以下给定代码时,我都使用 oracle 11g 作为我的数据库,其中表登录名包含条目 ('admin','admin')。当我在表单中输入值时,显示错误。此外,即使我打印了一些评论,我的控制台也没有显示任何输出。

我希望如果我以 homepagge.jsp 的形式输入 'admin','admin',IndexAdmin.jsp 页面应该打开。

我的编码如下

请帮忙,我是 j2ee 和 html 的新手

请尽快回复

主页.jsp

            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN" dir="ltr">
<head profile="http://gmpg.org/xfn/11">
<title>Test Turf Corporation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="imagetoolbar" content="no" />
<link rel="stylesheet" href="styles/layout.css" type="text/css" />
<script>
function validateFunction()
{
var username=document.forms["login"]["username"].value;
var password=document.forms["login"]["password"].value;
if (username==null || username=="" && password==null || password=="")
{
document.getElementById("error_username").innerHTML = "Enter Username and Password";
return false;
}
if (username==null || username=="")
{
document.getElementById("error_username").innerHTML = "no name";
return false;
}
if (password==null || password=="")
{
document.getElementById("error_username").innerHTML = "Enter Password";
return false;
}
return true;
}
</script>

</head>
<body id="top">
<div class="wrapper col1">
<div id="head" style="height:150px;">
<h1><a href="#">TestTurf</a></h1>
<p>Online Test Website</p>
<div class="login" style="width:45%;float:right; margin-top: 1%; margin-bottom: 5%;margin-right:0;margin-left:70%; height:200px;">
<form id="login" action="/ot/LoginValidationServlet" method="post" onsubmit="return validateFunction();">

<table border="0" style="border: none;">
<tr>
<td style="border: none;">Username</td>
<td style="border: none;">Password</td><td style="border: none;"></td>
</tr>
<tr><td style="border: none;"><input name="username" id="username" type="text"/></td>
<td style="border: none;"><input name="password" id="password" type="password"></input></td><td style="border: none;">
<input type="submit" name="login" value="Log In" class="submit" title="SUBMIT" style="background-color:#3D73B1; color:white; width:80px; height: 25px; border: none;"/></td></tr>
<tr><td style="border: none;">Not a User?<a href="login.html" style="color:yellow;">Register Here</a></td><td style="border: none;">
<a href="" style="color:yellow;">Forgot Password</a></td></tr>
</table></form>


</div>

<div id="topnav" style="margin-top: 4.25%;">
<ul>
<li><a class="active" href="homepage.jsp">Home</a></li>
<li><a href="#">Syllabus</a>
<ul>
<li><a href="Subject1.jsp">ADA</a></li>
<li><a href="TOC.jsp">TOC</a></li>
<li><a href="CSA.jsp">CSA</a></li>
</ul>
</li>

<li class="last"><a href="#">About us</a></li>
</ul>
</div>

</div>
</div>
<div class="wrapper col2">
<div id="gallery">
<ul>
<li class="placeholder" style="background-image:url(images/demo/m.jpg);">Image Holder</li>
<li><a class="swap" style="background-image:url(images/demo/b1.gif);" href="#gallery"> <strong>Services</strong><span><img src="images/demo/m1.jpg" alt="" /> </span> </a></li>
<li><a class="swap" style="background-image:url(images/demo/b2.gif);" href="#gallery"><strong>Products</strong><span><img src="images/demo/hd3.jpg" alt="" /></span></a></li>
<li class="last"><a class="swap" style="background-image:url(images/demo/b3.gif);" href="#gallery"><strong>Company</strong><span><img src="images/demo/images.jpg" alt="" /> </span></a></li>
</ul>
<div class="clear"></div>
</div>
</div>

<div class="wrapper col5">
<div id="footer">

<!-- End Contact Form -->

<!-- End Company Details -->
<div id="copyright">
<p class="fl_left">Copyright &copy; 2014 - All Rights Reserved - <a href="#">Test Turf</a></p>
<br class="clear" />
</div>
<div class="clear"></div>
</div>
</div>
</body>
</html>

我的小服务程序

 LoginValidationServlet.java

package onlinetest;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
* Servlet implementation class LoginValidationServlet
*/
public class LoginValidationServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public LoginValidationServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.print("Servlet 2");
LoginService oLoginService = new LoginService();
String username=request.getParameter("username");
String password=request.getParameter("password");
System.out.print("Servlet 1");

long result=oLoginService.loginService(username,password);

if(result==1){
HttpSession session=request.getSession(true);
session.setAttribute("username", username);
System.out.print("Servlet 2");
request.getRequestDispatcher("IndexAdmin.jsp").forward(request, response);

}

else
{
System.out.print("Servlet");
//response.sendRedirect("LoginError.jsp");
}
}

}




LoginService.java

package onlinetest;
mport java.io.IOException;

public class LoginService {

public long loginService(String username,String password) throws IOException {
long role=1;
System.out.print("Service class 1");
//loginDAO ologinDAO=new loginDAO();
// role=ologinDAO.validateLoginDetails(username,password);
System.out.print("Service class");
return role;
}
}




loginDAO.java

package onlinetest;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class loginDAO {
@SuppressWarnings("finally")
public long validateLoginDetails(String username, String password) throws IOException {

Connection con = null;
Statement stmt = null;
ResultSet rs = null;
long role = 0;
String query = "select username,password,role from login where username like '"+ username + "' and password like '" + password + "'";

String url="jdbc:oracle:thin:ot/bhumika@BHUMIKA:1521:XE";

try {

//String url="jdbc:oracle:thin:@192.168.43.31:1521:XE";

System.out.println("Query 1 executed");

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
//Class.forName("oracle.jdbc.driver.OracleDriver()").newInstance();
System.out.println("Query 2 executed");
// con=DriverManager.getConnection(url,"employee","bhumika");
con=DriverManager.getConnection(url);
stmt = con.createStatement();
System.out.println("Query 3 executed");
rs = stmt.executeQuery(query);
System.out.println("Query 4executed");

if (rs.next()) {
role = rs.getLong("role");
}
return role;

} catch (SQLException e) {
System.out.print("DAO class not connected");
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if(rs != null)
rs.close();
if(stmt != null)
stmt.close();
if(con !=null)
con.close();
} catch (SQLException e) {
System.out.print("DAO class not connected");
// TODO Auto-generated catch block
e.printStackTrace();
}
return role;

}

}

}





login.java

package onlinetest;

public class login {
String username;
String password;
long role;

public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public long getRole() {
return role;
}

}



IndexAdmin.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN" dir="ltr">
<head profile="http://gmpg.org/xfn/11">
<title>Test Turf Corporation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="imagetoolbar" content="no" />
<link rel="stylesheet" href="styles/layout.css" type="text/css" />
</head>
<body id="top">
<div class="wrapper col1">
<div id="head">
<h1><a href="#">TestTurf</a></h1>
<p>Online Test Website</p>
<div id="topnav">
<ul>
<li><a class="active" href="homepage.jsp">Home</a></li>
<li><a href="#">Syllabus</a>
<ul>
<li><a href="Subject1.jsp">ADA</a></li>
<li><a href="TOC.jsp">TOC</a></li>
<li><a href="CSA.jsp">CSA</a></li>
</ul>
</li>
<li><a href="#">Add Questions</a></li>
<li><a href="full-width.html">Test</a>
<ul>
<li><a href="#">Create Test</a></li>
<li><a href="#">Edit Test</a></li>
<li><a href="#">Delete Test</a></li>
</ul>
</li>
<li class="last"><a href="#">Results</a></li>

</ul>
</div>
<div id="search">
<h4 style="text-align: right;">

Welcome <%=session.getAttribute("username") %> &nbsp; <a href="#">Logout</a>
</h4>

</div>
</div>
</div>
div class="wrapper col2">
<div id="gallery">
<ul>
<li class="placeholder" style="background-image:url(images/demo/m.jpg);">Image Holder</li>
<li><a class="swap" style="background-image:url(images/demo/b1.gif);" href="#gallery"><strong>Services</strong><span><img src="images/demo/m1.jpg" alt="" /></span> </a></li>
<li><a class="swap" style="background-image:url(images/demo/b2.gif);" href="#gallery"><strong>Products</strong><span><img src="images/demo/hd3.jpg" alt="" /></span> </a></li>
<li class="last"><a class="swap" style="background-image:url(images/demo/b3.gif);" href="#gallery"> <strong>Company</strong><span><img src="images/demo/images.jpg" alt="" /></span></a></li>
</ul>
<div class="clear"></div>
</div>
</div>

<div class="wrapper col5">
<div id="footer">

<!-- End Contact Form -->

<!-- End Company Details -->
<div id="copyright">
<p class="fl_left">Copyright &copy; 2014 - All Rights Reserved - <a href="#">Test Turf</a></p>
<br class="clear" />
</div>
<div class="clear"></div>
</div>
</div>
</body>
</html>

最佳答案

该错误表示应用服务器(Tomcat)找不到/ot/LoginValidationServlet 的路径。看起来您正在使用独立的 JEE/Tomcat 解决方案,因此您可能想查看 web.xml 文件中到 LoginValidationServlet 的 servlet 映射。像这样:

<servlet-mapping>
<servlet-name>LoginValidationServlet</servlet-name>
<url-pattern>/LoginValidationServlet</url-pattern>
</servlet-mapping>

引用this article获取更多信息。

关于Eclipse Java EE 和 Tomcat 6 : Error 404 requested resource not available,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22498103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com