java - 我想将 Servlet 作为第一个文件调用

标签 java jsp servlets

我想调用 Servlet 作为第一个文件来像欢迎文件一样执行。

在此 servlet 中,我从数据库检索数据并将其渲染到显示页面的第一页。

我需要的是当我运行程序时

要么

url should be-http://localhost:8083/projectName/servletUrl

not http://localhost:8083/projectName/

if url is http://localhost:8083/projectName this should hit my servlet(/servletUrl) not welcome file.

最佳答案

编辑此文件WebContent->WEB-INF->lib->web.xml

It will only be visible if you have ticked the Generate web.xml deployment descriptor while creating the project.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"          
xmlns="http://xmlns.jcp.org/xml/ns/javaee"    
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID"    
version="3.1">
<display-name>Database_Conn</display-name>
<welcome-file-list>
    <welcome-file>ServletURLpattern</welcome-file>
 </welcome-file-list>
</web-app>

关于java - 我想将 Servlet 作为第一个文件调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30780313/

相关文章:

java - JSTL 标签在 Eclipse 中不起作用

java - 添加错误页面会阻止 tomcat 7 中的所有 servlet

http - 当拒绝客户端身份验证时让 servlet 给出 403 响应

java - 检测版本 Tomcat 服务器 (JSP/Servlet)

java - 指定 URL 地址。 Apache 汤姆猫

java - 动态语言开/关 Java JVM

java - 使用线程和 USB 连接后应用程序屏幕空白

java - 带有标题的列表 Activity 黑屏

java - SpringBoot 应用程序一直重启(重启循环) - spring.devtools

javascript - 为应用程序创建 session 超时