关于webapp-SRVE0278E:添加servlet映射时出错->/*和servlet映射的url路径的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Eclipse开发环境创建Serv
关于webapp-SRVE0278E:添加servlet映射时出错-> / *和servlet映射的url路径的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Eclipse 开发环境创建 Servlet3.0 Maven WebApp 项目、Eclipse新建Servlet时候,不会自动生成mapping到web.xml,而是在代码中加入注解@WebServlet、HTTP状态500-实例化servlet类pkg.coreServlet时出错、Java Servlet – 将servlet映射到每个URL但字符串等相关知识的信息别忘了在本站进行查找喔。
本文目录一览:- webapp-SRVE0278E:添加servlet映射时出错-> / *(servlet映射的url路径)
- Eclipse 开发环境创建 Servlet3.0 Maven WebApp 项目
- Eclipse新建Servlet时候,不会自动生成mapping到web.xml,而是在代码中加入注解@WebServlet
- HTTP状态500-实例化servlet类pkg.coreServlet时出错
- Java Servlet – 将servlet映射到每个URL但字符串
webapp-SRVE0278E:添加servlet映射时出错-> / *(servlet映射的url路径)
我已经设定了值
<jsp-attribute name="fileServingEnabled" value="false"/>
根据IBM支持讨论。
但我也收到此错误:
webapp - SRVE0278E: Error while adding servlet mapping --> /*.
我正在使用Spring Boot 1.4.3.RELEASE和传统的Websphere 9.0.0.1。
非常感谢您的帮助。
答案1
小编典典检查此页面配置JSP引擎参数。应通过以下方式指定:
<enable-file-serving value="false"/>
不是<jsp-attribute>
元素。
这是来自文档的示例:
<?xml version="1.0" encoding="UTF-8"?><web-ext xmlns="http://websphere.ibm.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd" version="1.0"> <default-error-page uri="error.jsp"/> <jsp-attribute name="useThreadTagPool" value="true" /> <jsp-attribute name="verbose" value="false" /> <jsp-attribute name="deprecation" value="false" /> <jsp-attribute name="reloadEnabled" value="true" /> <jsp-attribute name="reloadInterval" value="5" /> <jsp-attribute name="keepgenerated" value="true" /> <jsp-attribute name="trackDependencies" value="true" /> <reload-interval value="9"/> <auto-encode-requests value="true"/> <auto-encode-responses value="false"/> <enable-directory-browsing value="false"/> <enable-file-serving value="false"/> <pre-compile-jsps value="false"/> <enable-reloading value="true"/> <enable-serving-servlets-by-class-name value="true"/></web-ext>
Eclipse 开发环境创建 Servlet3.0 Maven WebApp 项目
- 在 eclipse 中创建 Maven WebApp 项目; 初步文件结构已经建好,但是可以看到项目名称左侧有错误显示
index.jsp 文件有一个 error ; Error 的原因是在 pom.xml 文件中还没有配置 web 项目的依赖,打开 pom.xml 文件,添加 JavaWeb 需要的 Servlet、JSP、JSTL 等依赖;
由于每个人本地的 JDK 版本可能不同,因此在 pom.xml 中来配置 jdk 的版本,以后就不用在去手动更改 jdk 的版本了
在 pom.xml 中添加如下代码:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dayuanapp</groupId>
<artifactId>secondweb</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>secondweb Maven Webapp</name>
<url>http://maven.apache.org</url>
<!--定义一个全局变量,统一管理版本号 -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.3.9.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- spring相关的依赖的jar包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.33</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- 数据库相关 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.31</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.4</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- JSP -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<!-- JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<finalName>secondweb</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
2. 默认建立的 webapp 版本为 2.3, 在 eclipse 中默认无法修改,因此打开项目的根目录下,
./settings/org.eclipse.wst.common.project.facet.core.xml 文件,修改 <installed facet="jst.web" version="3.0"/>
3. 删除 web.xml 文件,右键点击项目,Java EE Tools>Generate Deployment Descriptor Stub
右键项目名称,Maven>Update Project...
- Maven 更改本地仓库、默认中央仓库的配置
在 maven 的安装目录下的 conf/settings.xml 文件中进行设置即可,配置代码如下:
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>D:\Program Files (x86)\maven_repository</localRepository>//指定了本地仓库的位置
<mirrors>
<!-- 这里是配置了阿里云的仓库,下载速度非常快 -->
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
<mirror>
<!--This is used to direct the public snapshots repo in the
profile below over to a different nexus group -->
<id>nexus-public-snapshots</id>
<mirrorOf>public-snapshots</mirrorOf>
<url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url>
</mirror>
</mirrors>
Eclipse新建Servlet时候,不会自动生成mapping到web.xml,而是在代码中加入注解@WebServlet
现象:
用Eclipse新版本新建servlet时候,发现创建Servlet后,Eclipse不会自动在web.xml中生成该Servlet对应的mapping信息,而是在Servlet代码中加入注解@WebServlet,如下
分析:
查找文档发现,这是Servlet3.0新特性(得Tomcat7.0版本及以上),@WebServlet 用于将一个类声明为 Servlet,该注解将会在部署时被容器处理,容器将根据具体的属性配置将相应的类部署为 Servlet。该注解具有下表给出的一些常用属性(以下所有属性均为可选属性,但是 value 或者 urlPatterns 通常是必需的,且二者不能共存,如果同时指定,通常是忽略 value 的取值)
解决方法:
在@WebServlet 中定义Servlet的name、urlPatterns等信息
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
@WebServlet(
displayName = "This is Login Action", //描述
name = "LoginAction", //servlet名称
urlPatterns = { "/servlet/LoginAction" },//url
loadOnStartup = 1, //启动项
initParams = { @WebInitParam(name = "username", value = "张三") }//初始化参数
)
public class LoginAction extends HttpServlet {
/**
* Constructor of the object.
*/
public LoginAction() {
super();
}
}
Servlet的访问URL是Servlet的必选属性,可以选择使用urlPatterns或者value定义。
像上面的LoginAction可以描述成@WebServlet(name="LoginAction",value="/LoginAction")。
也定义多个URL访问:
如@WebServlet(name="LoginAction",urlPatterns={"/LoginAction","/LoginAction2"})
或者@WebServlet(name="LoginAction",value={"/LoginAction","/LoginAction2"})
这样的简化形式也可以,相当于设置了name和urlPattern
@WebServlet("/servlet/LoginAction")
在新建Servlet时候在URL mapping中可以直接输入
HTTP状态500-实例化servlet类pkg.coreServlet时出错
我正在创建简单的servlet并将其部署在tomcat服务器中,但是出现以下错误:
HTTP状态500-实例化servlet类pkg.coreServlet时出错
Tomcat服务器上的文件结构:
webapps | - aarya | - WEB-INF | -web.xml -src(folder) | -pkg | -coreServlet.class
web.xml:
<?xml version="1.0" encoding="UTF-8"?><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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><servlet> <servlet-name>aaryaservlet</servlet-name> <servlet-class>pkg.coreServlet</servlet-class></servlet><servlet-mapping> <servlet-name>aaryaservlet</servlet-name> <url-pattern>/coreServlet</url-pattern> </servlet-mapping></web-app>
coreServlet.java:
package pkg;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class coreServlet extends HttpServlet{ /** * */ private static final long serialVersionUID = 1L;public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { PrintWriter out = res.getWriter(); res.setContentType("text/html"); out.println("this is First servlet Example "); }}
我给的url是http://localhost:8080/aarya/coreServlet
我尝试通过重新启动tomcat来尝试,但出现了同样的错误。我在哪里做错了?
答案1
小编典典不要将src文件夹放在WEB-INF目录中!!
Java Servlet – 将servlet映射到每个URL但字符串
<servlet> <servlet-name>MyServ</servlet-name> <servlet-class>MyServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>MyServ</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
我需要以/ static /开头的URLS,它应该从静态WEB-INF提供给它们.也就是说,MyServ应该服务于/ static.
我怎样才能做到这一点?
更新:要澄清,我想要的是:
/ * / – 转到MyServ
/static/dir/file.css – Jetty从/ dir /中提供静态file.css.
我不知道web.xml要做什么,或者把静态文件放在哪里.
我尝试添加:
<servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/static/*</url-pattern> </servlet-mapping>
但是,当我去/静态/ URL,我只是得到:
HTTP ERROR 404 Problem accessing /static/dir/file.css. Reason: Not Found Powered by Jetty://
我不知道我的web.xml是否错误,或者我只是将文件放在错误的地方(我已经在src / main / webapp和src / main / webapp / lib / meta-inf /资源/)
码头
我正在使用码头.我想避免任何其他层,如Nginx,Apache等.
要赢得赏金,请确保您回答Jetty的作品.
解决方法
Rule for URL path mapping:
It is used in the following order. First successful match is used with no further attempts.
- The container will try to find an exact match of the path of the request to the path of the servlet. A successful match selects the servlet.
- The container will recursively try to match the longest path-prefix. This is done by stepping down the path tree a directory at a time,using the ’/’ character as a path separator. The longest match determines the servlet selected.
- If the last segment in the URL path contains an extension (e.g. .jsp),the servlet container will try to match a servlet that handles requests for the extension. An extension is defined as the part of the last segment after the last ’.’ character.
- If neither of the prevIoUs three rules result in a servlet match,the container will attempt to serve content appropriate for the resource requested. If a “default” servlet is defined for the application,it will be used.
所以它将匹配/ static /的规则,并停止在那里.
关于webapp-SRVE0278E:添加servlet映射时出错-> / *和servlet映射的url路径的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Eclipse 开发环境创建 Servlet3.0 Maven WebApp 项目、Eclipse新建Servlet时候,不会自动生成mapping到web.xml,而是在代码中加入注解@WebServlet、HTTP状态500-实例化servlet类pkg.coreServlet时出错、Java Servlet – 将servlet映射到每个URL但字符串等相关知识的信息别忘了在本站进行查找喔。
本文标签: