我已web.xml
为我的应用程序手动配置.现在,我在运行我的应用程序时遇到了问题.我正试图servlet
从我的jsp
页面访问我的.但是,它正在抛出错误page not found
.
servlet位于文件夹下方
<application folder>/WEB-INF/classes/<package>
Run Code Online (Sandbox Code Playgroud)
那么,究竟应该是在Servlet中的条目url-pattern
和servlet-mapping
.这样,servlet
可以通过URL访问.
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>workflow.WDispatcher</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>*NEXTEVENT*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
以上是Tomcat的片段web.xml
.*NEXTEVENT*
启动时的URL模式抛出
java.lang.IllegalArgumentException:servlet映射中的<url-pattern>无效
如果有人能提示错误,将不胜感激.
tomcat web.xml servlets illegalargumentexception servlet-mapping
我正在阅读Head First JSP和Servlets一书.我正在浏览servlet的映射.我怀疑的是
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>com.avinash.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/ServletBeer.do</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
url-pattern
以正斜杠(/
)开头?/
)代表什么?它代表我们的webapp名称吗?url-pattern
不以正斜杠(/
)开头会发生什么?/
)开头的规范吗?在书中明确提到:
不要忘记url-pattern中的正斜杠(/).
你可以解释吗?
这是我的web.xml:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
当我导航到:
http://localhost:8080/LearningRoot/index.xhtml
Run Code Online (Sandbox Code Playgroud)
我可以看到页面很好,但是当我导航到:
http://localhost:8080/LearningRoot/
Run Code Online (Sandbox Code Playgroud)
我收到错误:
发生错误:
FacesServlet不能具有/*的url模式.请定义一个不同的url模式.
但为什么?
这是我的欢迎档案:
<welcome-file-list>
<welcome-file>/index.xhtml</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud) 我正在开发一个JSF 2 Web应用程序.对于声望的purpouses我希望每个URL以.jsf
扩展名结尾.现在结束了.xhtml
.如果我将其直接更改为.jsf
Web浏览器地址栏,则会显示HTTP 500错误.
我该怎么设置它.jsf
?
我正在尝试在我的Android应用程序中加入GCM(谷歌云消息).为此,我一直在关注本教程.下面的评论报告成功,所以问题肯定在我身边,而不是教程.
信息 - 我正在运行最新的Java for Java EE Tomcat版本8(最新版)
这是尝试运行tomcat服务器时的控制台错误:
Caused by: java.lang.IllegalArgumentException: Servlet mapping specifies an unknown servlet name GCMBroadcast
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3071)
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3050)
at org.apache.catalina.startup.ContextConfig.configureContext(ContextConfig.java:1372)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1176)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:771)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5066)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
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">
<servlet>
<servlet-name>com.avilyne.gcm.GCMBroadcast</servlet-name>
<servlet-class>com.avilyne.gcm.GCMBroadcast</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GCMBroadcast</servlet-name>
<url-pattern>/gcmbroadcast</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Run Code Online (Sandbox Code Playgroud)
我的index.jsp文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html …
Run Code Online (Sandbox Code Playgroud) jsp tomcat servlets illegalargumentexception servlet-mapping
我得到这样的异常:
javax.servlet.ServletException: Could not resolve view with name 'htmlviews/index.html' in servlet with name 'dispatcher'
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1211)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Run Code Online (Sandbox Code Playgroud)
当我尝试连接到完全Java配置的Spring Web服务时。
我的配置类:
@Configuration
@EnableWebMvc
@ComponentScan({"config", "controller"})
public class MyWebConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/htmlviews/**").addResourceLocations("/htmlviews/");
}
}
Run Code Online (Sandbox Code Playgroud)
初始化器:
public class WebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[]{MyWebConfig.class};
}
protected Class<?>[] getServletConfigClasses() {
return null;
}
protected String[] getServletMappings() {
return new String[]{"/"};
}
}
Run Code Online (Sandbox Code Playgroud)
和控制器:
@Controller
public …
Run Code Online (Sandbox Code Playgroud) 当我尝试运行我的项目时,我收到错误
Caused by: java.lang.IllegalArgumentException: Servlet mapping specifies an unknown servlet name dispatcher
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3156)
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3135)
at org.apache.catalina.startup.ContextConfig.configureContext(ContextConfig.java:1372)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1176)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:771)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:95)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Run Code Online (Sandbox Code Playgroud)
我的web.xml
:
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)