servlets 相关问题

Servlet是在服务器机器上运行的Java应用程序编程接口(API),它可以拦截客户端发出的请求,并可以相应地生成/发送响应。

jsp中的动态下拉列表

我有一个动态的下拉列表,那么如何迭代并将列表值插入下拉列表中? var questionids = {“姓名”,“年龄”,“吸烟者”,“饮酒者”,“拜访丹尼斯特”}; 我有一个动态的下拉列表,那么如何迭代并将列表值插入下拉列表中? var questionids = {"Name", "Age", "Smoker", "Drinker", "Visit Denist"}; <select name="questionid" id="questionids"> <c:forEach var="questionids" items="${questionids}"> <option value="">${questionids}</option> </c:forEach> </select> 我按照上面的方法试过了。它不工作。我还需要每个选项的值应该自动递增,例如,第一个选项值为 1,第二个选项值为 2。e.t.c 任何人都可以提出解决方案吗 这是正确的方法,但你必须在var中给<c:forEach>另一个名字,如下所示: var questionids = {"Name", "Age", "Smoker", "Drinker", "Visit Denist"}; <select name="questionids" id="questionids"> <c:forEach var="questionid" items="${questionids}"> <option value="${questionid}">${questionid}</option> </c:forEach> </select> <% java.util.HashMap map = new java.util.HashMap(); map.put("0", "Name"); map.put("1", "Age"); map.put("2", "Smoker"); map.put("3", "Drinker"); map.put("4", "Visit Denist"); pageContext.setAttribute("map", map); %> <select name="questionid" id="questionids" > <c:forEach items="${map}"> <option value="${items.key}">${items.value}</option> </c:forEach> </select> <select name="questionid" id="questionids"> </select> 您可以使用 javascript 动态构建选择。您可能希望使用 arr 值作为选项值。如果你想使用增量,你可以创建一个 arr 并循环它们。 var questionids = {"Name", "Age", "Smoker", "Drinker", "Visit Denist"}; // var valuesArr = [1, 2, 3, 4, 5]; $.each(questionids , function(i, e) { $('#questionids').append("<option value='"+e+"'>"+e+"</option>"); // $('#questionids').append("<option value='"+valuesArr[i]+"'>"+e+"</option>"); });

回答 0 投票 0

java.io.IOException:写入服务器时出错

在我的项目中,我正在尝试将文件发送到 Amazon S3。代码现在可以运行,但有时会发生错误,我无法在 S3 上看到该文件。下面的日志: java.io.IOException:写入服务器时出错...

回答 1 投票 0

我的表单提交按钮发送新参数而无法保留旧参数的原因是什么?

我目前正在努力开发利用JSP/Servlet 的流行游戏“猜随机数”。但是,我遇到了表单参数提交过程的问题,因为...

回答 0 投票 0

即使变量名正确,java servlet 输入到错误的数据库

我有两个不同的实体,一个是 MyCustomer,一个是 MySalesman。数据库以某种方式在角色和地址之间切换 MySalesman 实体中的部分代码 @实体 公开课

回答 0 投票 0

javax.servlet.ServletException:类 [org.springframework.web.servlet.DispatcherServlet] 不是 servlet

我正在使用以下配置(使用 web.xml 和 org.springframework.web.servlet.DispatcherServlet)在 Tomcat 8.5.81 上部署 Spring 6.0.5。 我的web.xml配置如下: 我正在使用以下配置在 Tomcat 8.5.81 上部署 Spring 6.0.5(使用 web.xml 和 org.springframework.web.servlet.DispatcherServlet)。 我的web.xml配置如下: <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> </servlet> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/dispatcher-config.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> dispatcher-config.xml如下: <mvc:annotation-driven/> <mvc:resources mapping="/resources/**" location="/resources/"/> <context:component-scan base-package="org.mainPackage" /> <context:annotation-config/> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/WEB-INF/views/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> 最后pom.xml相关依赖如下: <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <java.version>17</java.version> <tomcat.version>8.5.81</tomcat.version> <servlet-api.version>3.1.0</servlet-api.version> </properties> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>6.0.5</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>6.0.5</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>6.0.5</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>jakarta.servlet.jsp.jstl</groupId> <artifactId>jakarta.servlet.jsp.jstl-api</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> 错误的根本原因是: java.lang.ClassCastException: class org.springframework.web.servlet.DispatcherServlet cannot be cast to class javax.servlet.Servlet (org.springframework.web.servlet.DispatcherServlet is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @4ac6da24; javax.servlet.Servlet is in unnamed module of loader java.net.URLClassLoader @28c97a5) 为什么会这样?以及如何解决这个问题? 谢谢。 Spring 6 已经完全从javax 迁移到了jakarta。 考虑到这一点,其他图书馆需要更新。 Tomcat 8.5 到 Tomcat 10. JDK 1.8 到 JDK17. 另外请记住,任何 javax 库都需要替换为使用 jakarta 的库。 我认为替代品是 <!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api --> <dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>6.0.0</version> <scope>provided</scope> </dependency> 或者您可以简单地保留您的 Tomcat 和 JDK 版本,但使用 Spring 5。 简而言之 javax 适用于 Spring 5,以及 Tomcat 10 之前的任何 Tomcat。 jakarta 库适用于 Spring 6、Tomcat 10 和最低 JDK17。 你不能混合使用 jakarta 和 javax,因为它们不兼容,除非你准备好手动重命名包。

回答 1 投票 0

Websphere 中的 Spring boot 部署

我们正在尝试使用 Spring data Jpa 将 Java 8 Spring boot 应用程序部署到 IBM WebSphere 8.5.5.21 服务器中。该应用程序在本地运行良好,但我们无法使其在 WebSphere 中运行。 ...

回答 3 投票 0

build-impl.xml:1058: 模块尚未部署

Apache Netbeans 16 和 Tomcat 10 错误 找不到合适的解决方案,如果有人知道解决方案,请提供帮助我已经尝试了几种方法,例如允许 apache tom 中的用户获得所有权限...

回答 0 投票 0

如何在servlet中添加环境值

我们有dev、predev、uat和prod,我需要编写代码来实现不同的环境,我们的应用程序是在servlets中开发的。 如果可能请分享我的代码 谢谢

回答 1 投票 0

在 java servlet 中配置重写阀

任何人都可以分享我如何使用 java servlet 在 apache tomcat 中详细配置重写阀,我尝试了很多方法但没有用。 在 context.xml 中,我添加了 任何人都可以分享我如何使用 java servlet 在 apache tomcat 中详细配置重写阀,我尝试了很多方法但没有用。 在context.xml中,我添加了 <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" /> 并在 WEB-INF 中创建 rewrite.config RewriteRule ^app/(.+)$ w/index.jsp?title=$1 [L]

回答 0 投票 0

从 jsp 网页获取数据作为字符串类型后,我应该如何将数据作为日期类型插入到 oracle 中?

我正在使用 jsp、servlet、java、oracle 构建网站。 我会在用户注册时询问他们的生日。 我在 Oracle 的 MEMBER 表中将 BIRTHDATE 列作为日期类型。 我正在使用 jsp、servlet、java、oracle 构建网站。 我会在用户注册时询问他们的生日。 我在 Oracle 的 MEMBER 表中将 BIRTHDATE 列作为日期类型。 <div id="birthDateArea"> <label for= "birthDate">birthDate</label> <p><input type="text" class="form-control" id="birthDateInput" placeholder="ex)20020604" name="memBirthDate" required></p> </div>*** 当用户输入他们的生日,如“19990715”时,我想将它插入到 oracle 的表中。 所以我想在 servlet 上像这样获取用户的生日。 String memBirthDate = request.getParameter("memBirthDate"); 并使用下面的查询将其插入到 oracle 中。 <entry key="insertMember"> INSERT INTO MEMBER ( MEM_BIRTHDATE ) VALUES ( (TO_DATE)? ) </entry> 但是没用。我认为我的 oracle 查询中存在一些问题,但我不确定。 我该怎么办? 我试过这样得到生日 Date memBirthdate = request.getParameter("memBirthDate"); 但是它导致了很多错误,所以我放弃了使用 Date 类型。 避免遗留课程 切勿使用任何一个 Date 类。两者都是多年前被 JSR 310 中定义的现代 java.time 类所取代的可怕的日期时间遗留类的一部分。 LocalDate 对于仅限日期的值,请使用 LocalDate 类。 您的输入字符串符合 ISO 8601 标准格式 YYYYMMDD 的“基本”变体。所以使用预定义的格式化程序,DateTimeFormatter.BASIC_ISO_DATE. String input = "19990715" ; LocalDate birthDate = LocalDate.parse( input , DateTimeFormatter.BASIC_ISO_DATE ) ; 像下面这样写你的SQL。 提示:在所有数据库命名中使用尾随下划线以避免与保留关键字冲突。 SQL 标准明确承诺永远不会使用尾随下划线。请参阅我的这个答案。 另一个提示:为您的嵌入式 SQL 代码使用 文本块。 String sql = """ INSERT INTO member_ ( id_ , birth_date_ ) VALUES ( ? , ? ) ; """; 交换 LocalDate 对象以写入数据库。 myPreparedStatement.setObject( 2 , birthDate ) ; 从数据库中检索数据值时。 LocalDate birthDate = myResultSet.getObject( … , LocalDate.class ) ; 所有这些都在 Stack Overflow 上多次介绍过。搜索以了解更多信息。您将找到创建表格、插入行和检索行的示例应用程序的完整源代码。

回答 1 投票 0

混合内容页面是通过 HTTPS 加载的,但请求了不安全的资源该请求已被阻止,内容必须通过 HTTPS 提供

混合内容:'' 的页面是通过 HTTPS 加载的,但请求了不安全的资源 ''。此请求已被阻止;内容必须通过 HTTPS 提供。

回答 3 投票 0

没有为命名空间 / 和动作名称 register 映射的动作

我正在用 struts 2 做一个简单的网络应用程序。 下面是我的表单和对应的动作类结构。尝试注册新记录时出现以下错误。 注册.jsp <%@ page la...

回答 0 投票 0

MySql Servlet 插入操作失败

我正在演示 Java Servlet - MySql 应用程序。 以下是我的 ApplicationDAO 方法 public int registerUser(用户用户){ int rowsAffected = 0; 尝试 { 连接

回答 1 投票 0

JSP 没有正确地从来自 servlet 的数组中接收信息

我正在尝试创建一个项目,我在其中使用 servlet 将信息传递到 JSP 页面。问题是我无法让 JSP 生成我期望的内容。 为了进一步解释,在我返回的 servlet 中......

回答 0 投票 0

如何在 WAR 中使用注释定义 servlet 过滤器执行顺序

如果我们在 WAR 自己的 web.xml 中定义 webapp 特定的 servlet 过滤器,那么过滤器的执行顺序将与它们在 web.xml 中定义的顺序相同。 但是,如果我们定义...

回答 4 投票 0

从 vert.web.ext context.request() 获取 HttpServletRequest

我可能会问类似的问题 是否可以相互翻译 ServerHttpRequest 和 HttpServletRequest 我有一个旧的第 3 方 jar 库(无源代码),它接收/期望

回答 1 投票 0

通过方法发送“HEAVY”文件时出现问题。在 java 中使用 apache fileupload

我有一个非常严肃的问题,想象下一个场景。 您需要读取一个巨大的 zip 文件 (1gb),并且您需要将该 FILE 参数传递给另外 3 个方法,我该如何完成?

回答 0 投票 0

Java Servlet 问题打印 html

我正在尝试创建一个 servlet,它从我的数据库中检索信息,然后将其显示在板上。此外,我希望同一个板将点击信息发送到另一个 servlet,以便...

回答 0 投票 0

带有 WebAppContext 和 ServletContextHandler 的嵌入式 Jetty 创建问题

在运行 pytest 时出现以下错误:- AssertionError:预期的 http 状态 200,收到 405: 电子 电子 运行pytest出现如下错误:- AssertionError: Expected http status 200, received 405: <html> E <head> E <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> E <title>Error 405 HTTP method POST is not supported by this URL</title> E </head> E <body><h2>HTTP ERROR 405 HTTP method POST is not supported by this URL</h2> E <table> E <tr><th>URI:</th><td>/activity/1111111</td></tr> E <tr><th>STATUS:</th><td>405</td></tr> E <tr><th>MESSAGE:</th><td>HTTP method POST is not supported by this URL</td></tr> E <tr><th>SERVLET:</th><td>org.eclipse.jetty.servlet.ServletHandler$Default404Servlet-438bad7c</td></tr> E </table> 导致此错误的代码是: 在添加“//代码已添加”下方的代码行后,即使用 ServletContextHandler 时,此错误开始出现。基本上想捕获 jvm 指标,但在添加我常用的测试用例时,即使是简单的 Get 或 POST 请求也无法执行。 public static void main(String[] args) throws Exception { String basedir = prop("hs.webapp"); String logname = prop("hs.requestlog"); int serverPort = Integer.parseInt(prop("hs.port")); // very small queue - allow most queueing to happen upstream (haproxy) // max 50 queued, 300 active requests and an idle timeout of 50 seconds ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<Runnable>(50); QueuedThreadPool threadPool = new QueuedThreadPool(300, 10, 50000, queue); Server server = new Server(threadPool); HttpConfiguration http_config = new HttpConfiguration(); //http_config.setSecureScheme("https"); //http_config.setSecurePort(8443); http_config.setOutputBufferSize(65536); http_config.setRequestHeaderSize(8192); http_config.setResponseHeaderSize(8192); http_config.setSendServerVersion(false); http_config.setSendDateHeader(false); ServerConnector http = new ServerConnector(server, new HttpConnectionFactory(http_config)); http.setPort(serverPort); http.setIdleTimeout(120000); server.addConnector(http); LowResourceMonitor lowResourcesMonitor = new LowResourceMonitor(server); lowResourcesMonitor.setPeriod(5000); lowResourcesMonitor.setLowResourcesIdleTimeout(1000); lowResourcesMonitor.setMonitorThreads(true); lowResourcesMonitor.setMaxConnections(20000); lowResourcesMonitor.setMaxMemory(0); lowResourcesMonitor.setMaxLowResourcesTime(5000); server.addBean(lowResourcesMonitor); WebAppContext context = new WebAppContext(); context.setDescriptor(basedir + "WEB-INF/web.xml"); context.setResourceBase(basedir); context.setContextPath("/"); context.setErrorHandler(new PlaintextErrorHandler()); HandlerCollection handlers = new HandlerCollection(); RequestLogHandler requestLogHandler = new RequestLogHandler(); handlers.setHandlers(new Handler[]{context, new DefaultHandler(), requestLogHandler}); server.setHandler(handlers); NCSARequestLog requestLog = new CustomNCSARequestLog(logname); requestLog.setRetainDays(90); requestLog.setAppend(true); requestLog.setExtended(true); requestLog.setLogTimeZone("GMT"); requestLog.setLogLatency(true); requestLog.setPreferProxiedForAddress(true); requestLogHandler.setRequestLog(requestLog); /* // Configure StatisticsHandler. StatisticsHandler stats = new StatisticsHandler(); stats.setHandler(server.getHandler()); server.setHandler(stats); // Register collector. new JettyStatisticsCollector(stats).register(); // new QueuedThreadPoolStatisticsCollector(queuedThreadPool, "myapp").register(); server.setStopAtShutdown(true);*/ //Code Added ServletContextHandler servletContextHandler = new ServletContextHandler(); // servletContextHandler.setContextPath("/"); // context.setResourceBase(System.getProperty("java.io.tmpdir")); // server.setHandler(servletContextHandler); // Add default servlet context.addServlet(DefaultServlet.class, "/"); // Expose our example servlet. //context.addServlet(new ServletHolder(new ExampleServlet()), "/"); // Expose Promtheus metrics. servletContextHandler.addServlet(new ServletHolder(new MetricsServlet()), "/metrics"); // Add metrics about CPU, JVM memory etc. DefaultExports.initialize(); //server.setDumpAfterStart(true); //server.setSendServerVersion(false); server.start(); server.join(); } 如果需要更多信息或以上信息足以提供帮助,请告诉我。谢谢! 我能够在做时获得 JVM 指标 curl localhost:8002/metrics 输出:- jvm_buffer_pool_used_bytes{pool="mapped",} 0.0 jvm_buffer_pool_used_bytes{pool="direct",} 81920.0 # HELP jvm_buffer_pool_capacity_bytes Bytes capacity of a given JVM buffer pool. # TYPE jvm_buffer_pool_capacity_bytes gauge jvm_buffer_pool_capacity_bytes{pool="mapped",} 0.0 jvm_buffer_pool_capacity_bytes{pool="direct",} 81920.0 # HELP jvm_buffer_pool_used_buffers Used buffers of a given JVM buffer pool. # TYPE jvm_buffer_pool_used_buffers gauge jvm_buffer_pool_used_buffers{pool="mapped",} 0.0 jvm_buffer_pool_used_buffers{pool="direct",} 3.0 # HELP process_cpu_seconds_total Total user and system CPU time spent in seconds. # TYPE process_cpu_seconds_total counter process_cpu_seconds_total 5.42 # HELP process_start_time_seconds Start time of the process since unix epoch in seconds. # TYPE process_start_time_seconds gauge process_start_time_seconds 1.676981598495E9 # HELP process_open_fds Number of open file descriptors. # TYPE process_open_fds gauge process_open_fds 225.0 # HELP process_max_fds Maximum number of open file descriptors. # TYPE process_max_fds gauge process_max_fds 1048576.0 # HELP process_virtual_memory_bytes Virtual memory size in bytes. # TYPE process_virtual_memory_bytes gauge process_virtual_memory_bytes 4.659011584E9 # HELP process_resident_memory_bytes Resident memory size in bytes. # TYPE process_resident_memory_bytes gauge process_resident_memory_bytes 1.31592192E8 # HELP jvm_memory_pool_allocated_bytes_total Total bytes allocated in a given JVM memory pool. Only updated after GC, not continuously. # TYPE jvm_memory_pool_allocated_bytes_total counter 有一个链接但没有太大帮助: 带有 WebAppContext 和 ServletContextHandler 以及其他处理程序的嵌入式 Jetty

回答 0 投票 0

当我在数据库 URL 中启用公钥检索时,“不允许公钥检索”错误仍然发生

我得到一个空连接,因为不允许公钥检索很多人在尝试建立 JDBC 连接时遇到类似的错误,人们总是给出的答案是添加 ?...

回答 0 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.