相关疑难解决方法(0)

/ WEB-INF中的JSP返回"HTTP状态404请求的资源不可用"

我创建了一个JSP文件.

sample.jsp

<%@ page pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
  <head>
    <title>Insert title here</title>
  </head>
  <body>
    This is jsp program
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我把它放在samplejsp项目中.

samplejsp
 `-- WebContent
      `-- WEB-INF
           `-- sample.jsp
Run Code Online (Sandbox Code Playgroud)

我在以下网址上打开了它.

http://localhost:8080/samplejsp/sample.jsp

但它在浏览器中显示以下错误.

404错误

请求的资源(/sample.jsp)不可用.

jsp web-inf http-status-code-404

7
推荐指数
1
解决办法
7417
查看次数

调用servlet导致HTTP状态404"请求的资源不可用"

register在课堂上有一个servlet p1.我有一个JSP jsp1.jsp.我运行JSP文件并看到它,但是当我尝试应用于servlet时,Tomcat显示错误:

HTTP状态404

请求的资源(/ omgtuk/Register)不可用.

Servlet的:

@WebServlet("/register")
Run Code Online (Sandbox Code Playgroud)

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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>omgtuk</display-name>


 <servlet>
    <description></description>
    <display-name>register</display-name>
    <servlet-name>register</servlet-name>
    <servlet-class>p1.register</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>register</servlet-name>
    <url-pattern>/register</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>jsp1.jsp</welcome-file>
  </welcome-file-list>
</web-app>
Run Code Online (Sandbox Code Playgroud)

我正在使用Eclipse.

servlets http-status-code-404

6
推荐指数
1
解决办法
3万
查看次数

如何从JSP中的/ main/resources链接Web资源文件?

我的java webapp中有以下结构

-- main
   -- java
   -- resources
      -- lib
         -- css
            -- style.css
   -- webapp
      -- WEB-INF
         -- web.xml
      --index.jsp
Run Code Online (Sandbox Code Playgroud)

如何将style.css链接到我的索引jsp?

<link rel="stylesheet" href="???">
Run Code Online (Sandbox Code Playgroud)

这应该是什么?

提前致谢

resources jsp maven

6
推荐指数
1
解决办法
5180
查看次数

找不到HTTP 404(未找到Servlet)

我是一名学生,正在学习使用jsp和servlet构建Web应用程序.我的Web应用程序项目自一个月以来工作正常,但今天突然表现得很奇怪.当我提交我的jsp页面时,它无法找到我的servlet.我已经使用servlet注释来映射请求.

以下是我的jsp: -

<form name=registration_form action="<%=application.getContextPath() %>/Registration" method="post">  
    First Name:</td><td><input type="text" name="firstName" required/></td></tr> 
    </form>
Run Code Online (Sandbox Code Playgroud)

以下是我的Servlet: -

package servlets;
    @WebServlet("/Registration")
    public class Registration extends HttpServlet {
        private static final long serialVersionUID = 1L;
        public Registration() {
            super();
        }

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

        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String firstName=request.getParameter("firstName"); 
            System.out.println(firstName);
        }
    }
Run Code Online (Sandbox Code Playgroud)

以下是我的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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee …
Run Code Online (Sandbox Code Playgroud)

java jsp tomcat servlets http

5
推荐指数
1
解决办法
4万
查看次数

Java - Servlet 404 错误

我是 servlet 编程的新手。

以下是我的示例 servlet 代码

示例.Java

public class Sample extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        res.setContentType("text/html");  
        PrintWriter pw=res.getWriter();  

        String name=req.getParameter("name");//will return value  
        pw.println("Welcome "+name);  
        pw.close();  
    }
}
Run Code Online (Sandbox Code Playgroud)

网页.xml

<web-app>
<servlet>
<servlet-name>sampleservlet</servlet-name>
<servlet-class>Sample</servlet-class>
<load-on-startup>1</load-on-startup> 
</servlet>
<servlet-mapping>
<servlet-name>sampleservlet</servlet-name>
<url-pattern>/Sample</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

索引.html

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="Sample" method="get">  
Enter your name<input type="text" name="name"><br>  
<input type="submit" value="login">  
</form> …
Run Code Online (Sandbox Code Playgroud)

java eclipse tomcat servlets

5
推荐指数
1
解决办法
2万
查看次数

Tomcat 将 servlet 转换为 javax.servlet.Servlet 而不是 jakarta.servlet.http.HttpServlet

我一直在徒劳地尝试实现 tomcat 9 的 jakarta servlet,而不是以前的 javax.servlet 实现(因为我的理解是 jakarta 包是前进的方向)。问题是,当我将浏览器指向我的 servlet 的 url 时,我收到以下错误...

java.lang.ClassCastException: class cti.nm.web.Index cannot be cast to class javax.servlet.Servlet (cti.nm.web.Index is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @48c76607; javax.servlet.Servlet is in unnamed module of loader java.net.URLClassLoader @621be5d1)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    org.apache.coyote.ajp.AjpProcessor.service(AjpProcessor.java:432)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:888)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:832)
Run Code Online (Sandbox Code Playgroud)

问题已经很明显了。Tomcat 正在尝试将我的 jakarta.servlet.http.HttpServlet 转换为 javax.servlet.Servlet,这显然不起作用。我无法想象的是如何告诉它 servlet 实际实现的类。

类本身被声明为...

package cti.nm.web;
import jakarta.servlet.http.HttpServlet;
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public class Index extends …
Run Code Online (Sandbox Code Playgroud)

tomcat servlets classcastexception maven

5
推荐指数
1
解决办法
6529
查看次数

如何通过单击JSP页面中的超链接或按钮将当前项传递给Java方法?

我有一个HTML表,其中包含从该表中显示的数据库中提取的行.我希望用户能够通过单击每行之外的删除超链接或按钮来删除行.

当用户点击每个删除超链接或按钮时,如何在页面上调用JSP函数,以便我可以从数据库中删除该行的条目?<a>or <button>标签究竟应该调用JSP函数到底是什么?

请注意,我需要调用JSP函数,而不是JavaScript函数.

jsp

4
推荐指数
1
解决办法
2万
查看次数

HTTP状态404 - 请求的资源(/ ProjectName /)不可用

在Tomcat服务器上运行Eclipse项目时出现以下错误:

HTTP状态404 - 请求的资源(/ ProjectName /)不可用.

浏览器地址栏中的URL是http://localhost:8080/ProjectName/.

我真的不知道我的文件中缺少什么.我Index.jsp/WebContent文件夹中有一个我的web.xml包含在下面的条目:

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)

eclipse jsp tomcat http-status-code-404 welcome-file

4
推荐指数
1
解决办法
7万
查看次数

HTTP状态404-Servlet [ServletName]不可用

问题:我的带有web.xml的index.jsp一直进入HTTP 404和500

我正在使用Tomcat6。

这是来自index.jsp:

  <legend>Registration</legend>
  <form action="./register"> <%-- Address from web.xml  --%>
    First name: <input type="text" name="firstName"><br>
    Last name: <input type="text" name="lastName"><br>
    <input type="submit" value="Register">
  </form>
Run Code Online (Sandbox Code Playgroud)

当我在注册时:

在此处输入图片说明

然后输入名称和姓氏,然后输入404,消息为:

HTTP状态404-Servlet注册Servlet不可用

类型状态报告

消息 Servlet注册Servlet不可用

描述所请求的资源(Servlet RegistrationServlet不可用)不可用。

Apache Tomcat / 6.0.35

您认为该错误的原因是什么?

该类RegistrationServlet在文件RegistrationServlet.java夹中的文件下src/coreservlets/

我检查了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/j2ee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
  <servlet>
    <servlet-name>ShowBalance</servlet-name>
    <servlet-class>coreservlets.ShowBalance</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ShowBalance</servlet-name>
    <url-pattern>/show-balance</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>RandomNumberServlet</servlet-name>
    <servlet-class>coreservlets.RandomNumberServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>RandomNumberServlet</servlet-name>
    <url-pattern>/random-number</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>RegistrationServlet</servlet-name>
    <servlet-class>coreservlets.RegistrationServlet</servlet-class>
  </servlet>
  <servlet-mapping> …
Run Code Online (Sandbox Code Playgroud)

java jsp tomcat servlets

4
推荐指数
1
解决办法
4万
查看次数

HTTP 状态 500 错误实例化 servlet 类

我正在编写一个 Web 应用程序并将其部署到 apache tomcat Web 容器。我遵循来自http://cse.csusb.edu/turner/java_web_programming/servlets/的简单教程

然后最终得到这个错误。我分别粘贴和 web.xml、website.xml 和我的代码文件的片段。

结构:

在此处输入图片说明

网页.xml:

<?xml version="1.0"?>
<web-app
     xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
     version="2.4">
   <servlet>
      <servlet-name>home</servlet-name>
      <servlet-class>website.web.HomeServlet</servlet-class>
   </servlet>
   <servlet-mapping>
      <servlet-name>home</servlet-name>
      <url-pattern>/home</url-pattern>
   </servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

HomeServlet.java

打包网站.web;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HomeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
               throws ServletException, IOException {
                  PrintWriter writer = resp.getWriter();
                  writer.println("<h1>Hello, World!</h1>");
               }        
}
Run Code Online (Sandbox Code Playgroud)

错误:

HTTP Status 500 - Error …
Run Code Online (Sandbox Code Playgroud)

java xml apache networking servlets

4
推荐指数
1
解决办法
6万
查看次数