我有一个HTML表,其中包含从该表中显示的数据库中提取的行.我希望用户能够通过单击每行之外的删除超链接或按钮来删除行.
当用户点击每个删除超链接或按钮时,如何在页面上调用JSP函数,以便我可以从数据库中删除该行的条目?<a>or <button>标签究竟应该调用JSP函数到底是什么?
请注意,我需要调用JSP函数,而不是JavaScript函数.
首先:我使用GlassFish 3.1 + Eclipse Java EE靛蓝。我想用javaee测试缓存解决方案,所以我做了一个虚拟应用程序。我有一个生成的大型数据库,并且列出,搜索,修改等一些数据。为此,我编写了一些基本的servlet,并使用GET参数进行调用。例如:/ app / list?page = product&pageSize = 100 ListServlet带有注释
@WebServlet({ "/ListServlet", "/list" })
Run Code Online (Sandbox Code Playgroud)
而且它就像一种魅力,我可以同时使用两个网址。因此,我需要一些其他的servlet(用于搜索,修改)。我创建了它们并以相同的方式注释。但是,当我键入url http://localhost/app/modify或/ app / search?id = 1时,出现错误404。我尝试编写一个非常虚拟的helloservlet,它打印了一个hello world消息,但没有用:错误404。我重新启动了玻璃鱼服务器和计算机,但没有帮助。
有什么问题?我错过了什么?
编辑:servlet是相同的程序包使用相同的导入...
我有一个问题,我正在尝试运行我的简单servlet,Hello.java.我在eclipse中创建它,然后将文件放在文件webapps/ServletTest/WEB-INF/classes夹中并编译它,Hello.class在同一文件夹中创建文件.然后我修改了我的web.xml文件以映射servlet并尝试通过以下地址运行它
http://localhost:8080/ServletTest/Hello
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用,给出以下错误
HTTP状态404 -
类型状态报告
信息
description请求的资源不可用.Apache Tomcat/7.0.42
web.xml文件中的映射如下所示:
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>Main.Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/Hello</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
servlet的代码:
package Main;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/Hello")
public class Hello extends HttpServlet {
private static final long serialVersionUID = 1L;
public Hello() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/html");
String path = request.getContextPath();
String ip = …Run Code Online (Sandbox Code Playgroud) 当我使用以下内容时web.xml,我的项目运行正常,我可以通过index.jsp页面看到"Hello World".我使用的是Netbeans 7.4和Apache tomcat 6.0.41
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
Run Code Online (Sandbox Code Playgroud)
但是,当我创建自己的servlet并使用以下时web.xml,=
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<servlet>
<servlet-name>TEST_Authenticate</servlet-name>
<servlet-class>restapi.TEST_Authenticate</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TEST_Authenticate</servlet-name>
<url-pattern>/TEST_Authenticate</url-pattern>
</servlet-mapping>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我最终在Apache Tomcat日志中收到以下错误:
Jul 24, 2014 9:36:14 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet TEST_Authenticate
java.lang.ClassNotFoundException: TEST_Authenticate
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1128)
at …Run Code Online (Sandbox Code Playgroud) 404 resource not found当Sun的J2EE自动处理的给定.WAR中的页面deploytool试图在同一个.WAR文件中加载Servlet 时,最有可能导致错误的罪魁祸首是什么?
例如:
HTTP状态404 - /MyServlet/MyServlet
类型状态报告
message/MyServlet/MyServlet
description请求的资源(/ MyServlet/MyServlet)不可用.
我有一个简单的servlet说 com.test.HelloWorld.class
然后我创建这些文件夹树:
WEB-INF -->
lib
classes -->
com -->
test -->
HelloWorld.class
web.xml
Run Code Online (Sandbox Code Playgroud)
其中web.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>helloworld</servlet-name>
<servlet-class>
com.test.HelloWorld
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloworld</servlet-name>
<url-pattern>/servlets</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
在我创建一个名为servlets.war的.war并将其放入GlassFish服务器的autodeploy dir之后.
在我指向url后:localhost:8080/servlets/helloworld但我有404错误.
为什么?什么是哇?
谢谢.
xml文件位于WebContent/WEB-INF/web.xml我的项目中.我正在使用Eclipse并运行Tomcat(它不是通过Eclipse安装的.我更喜欢它是一个单独的安装).
<?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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>EmployeeManagement</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>name</param-name>
<param-value>Pramod</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Registration</servlet-name>
<url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
当表单页面提交给servlet时它不起作用.我每次都会收到404错误.我一直遇到这个问题.有人请帮帮我.
我正在使用 Tomcat8 服务器,但出现以下错误。
它的网址是http://localhost:8080/WeatherWebApp当我提交详细信息时,它会出现此错误。这是 WeatherServlet.java 类
package org.akshayrahar;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class WeatherServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
WeatherServlet(){
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("again");
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("akshay rahar");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
Run Code Online (Sandbox Code Playgroud)
这是 web.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<web-app version="2.4" 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">
<display-name>WeatherWebApp</display-name> …Run Code Online (Sandbox Code Playgroud) 我有一个名为LoggingServlet的日志记录servlet,它覆盖了doGet和doPost方法,如下所示:
public class LoggingServlet extends HttpServlet {
private static final long serialVersionUID = 2L;
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
...do stuff here
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
...do stuff here
}
Run Code Online (Sandbox Code Playgroud)
我的web.xml看起来像这样:
<servlet>
<servlet-name>LoggingServlet</servlet-name>
<servlet-class>com.example.servlets.LoggingServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoggingServlet</servlet-name>
<url-pattern>/LoggingServlet/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
这是一个实现一些JavaScript的jsp的片段:
<script>
document.getElementById("ad_div").onmousedown = function () {
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","/LoggingServlet?bookie_id=<%= request.getParameter("id") %>&app_id=<%= request.getParameter("app_id") %>",true);
xmlhttp.send();
return true;
};
</script>
Run Code Online (Sandbox Code Playgroud)
我还有另一个通过Post请求调用LoggingServlet的jsp.现在我的问题:
怎么可能?
我正在为hello world创建一个简单的servlet来检查servlet是否正常工作,但在运行servlet并在运行servlet时映射web.xml文件后,它给了我一个错误.
我的代码:
请帮我解决我的问题??
我是java的新手,我只是尝试从Deployment Descriptor文件(web.xml)中读取初始化参数,但是出现了上述错误?
我web.xml和java文件编码编码附加快照.
我的直接结构是
c:\....tomcat\webapps\dd\web-inf\classes
Run Code Online (Sandbox Code Playgroud)
java类文件中没有错误.
成功编译的Java文件代码
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet2 extends HttpServlet {
String fileName;
public void init(ServletConfig config) throws ServletException {
super.init(config);
fileName = config.getInitParameter("logfilename");
}
protected void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException {
processRequest(request, response);
}
protected void processRequest(HttpServletRequest request,HttpServletResponse
response)throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println(fileName);
out.close();
}
}
Run Code Online (Sandbox Code Playgroud)
web.xml中
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app> …Run Code Online (Sandbox Code Playgroud)