问题标签 [servlet-2.5]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
url-rewriting - Redirection to Angular2 page from Servlet results in 404
I've an old application that is at Java 1.6, Servlet 2.5 and deployed as WAR on a Websphere Application Server 7.x version. Now, I'm trying to add a newly written page with Angular2 framework and typescript.
My web.xml has the following servlet mapping.
In our existing application, we pass GET requests with a query parameter to our servlet to address redirection.
http://localhost:9081/rootContext/MyControllerServlet?brand=brand1 http://localhost:9081/rootContext/MyControllerServlet?brand=brand2 and so on. To this, we have to add the newly created Angular2 page when the brand is brand3. So, http://localhost:9081/rootContext/MyControllerServlet?brand=brand3 should redirect to an Angular2 page.
MyControllerServlet.com
This was working good with the existing pages which are all JSPs. The newly added Angular2 page is called brand3.jsp with the following configuration.
webpack-dist-conf.js
The output block looks like this.
The publicPath was added as the main*.js and vendor*.js were giving 404 without the root context.
The routes.ts has the following root configuration
The challenge is when we redirect to brand3.jsp, we get a 404 with the following error.
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'rootContext/MyControllerServlet' Error: Cannot match any routes. URL Segment: 'rootContext/MyControllerServlet'
This redirection worked pretty good earlier, when the page was developed with Angular 1.6 version. We didn't even needed publicPath for rendering the main*.js and vendor*.js which are in the same folder of capmf.jsp.
The problem started arising only after upgrading to TypeScript and Angular2.
I've read that the Angular2 routes requires some server side configuration. To that effect, I have tried using tuckey's UrlRewriteFilter with following configuration.
web.xml
urlrewrite.xml
I know that URL rewriting is working as I could see debug statements. However, I haven't used it before and not sure, if I have configured it properly.
Additional note - We are using Maven3 to build the application and for Angular pages we are using
The question I have are -
- Is this happening because of tag? I'm not able to change the base href tag using the npm plugins. I get not a constructor error with base-href-webpack-plugin and webpack-base-href plugin
- Is publicPath the right way to deal when rootContext is not getting added for src javascript files?
- What else can I do to avoid the 404 error for brand3.jsp?
java - Tomcat 日志过滤器未正确编码响应正文
在将日志过滤器从使用javax.servlet.servlet-api:2.5
to调整3.0.1
为 Tomcat 时,我遇到了一个问题。
日志消息的一部分以 UTF-8 正确编码,而另一部分则存在一些编码问题(未知编码)。
问题:bufferedResponse.getContent()
返回一个奇怪编码的字符串
输出:
新添加的HttpServletResponse
in方法servlet-api:3.0.1
:
过滤器代码:
java - Jersey 2 状态码在 HttpServletResponseWrapper 中不可见
Java servlet API 直到 3.0 版才为 HttpServletResponse 提供 getStatus 方法。我用 getStatus 创建了一个 HttpServletResponseWrapper 来包装 HttpServletResponse 并在设置状态时捕获它。
这不适用于我的 Jersey 2 servlet。
我的 HttpServletResponseWrapper 是通过我的过滤器的 doFilter(request, wrapperResponse) 传递的。当 Jersey RESTful Servlet 是端点时,会调用 Filter 但不会调用 getStatus 方法。
有没有我错过的配置?
我使用响应生成器返回结果并设置状态。
Response.status(404).build(); Response.status(200).type(mediaType).entity(theEntity).build();
最好的问候
java - Jersey2 遵循什么?Servlet-2 或 Servlet-3 规范
我很想知道 Jersey2 是否遵循 Servlet-2.5 规范或 Servlet-3。我在我的 jersey webapp 项目中使用了 log4j2,它的配置方式取决于 Servlet 类型。
tomcat7 - Tomcat 6 vs 7 破坏了默认和 jsp servlet 请求 (404)
我们正在将大约 20 个 Web 上下文从 Tomcat 6.0.48 迁移到 Tomcat 7.0.76,但是我们遇到了由父级web.xml
( tomcat7\conf\web.xml
) 中配置的 servlet 处理的请求的问题。/some_file.html
问题是对, /some_file.jsp
,/images/some-image.jpg
的请求/index.xhtml
返回 404 NOT FOUND,而web.xml
在上下文中声明的其他自定义 servlet工作正常。多年来,所有 20 个上下文在 Tomcat 6 中都运行良好,但只有10 个在 Tomcat 7 上失败。我们比较了那些可以工作的和不能工作的,但它们非常不同(不足为奇),我们还没有发现问题。
测试
项目是在 Windows 下使用 Eclipse 部署的,一些测试是直接在 /webapps 上部署 WAR 文件执行的,结果相同。所有项目都是 Java 1.8 并且它们是 mavenized。测试包括部署一个工作上下文和一个不工作的上下文并导航到:、、/some_file.html
并查看响应是 200 还是 404。/some_file.jsp
/images/some-image.jpg
- 我们尝试将 javax.servlet.servlet-api(2.5 到 3.0.1)和 javax.servlet.jsp.jsp-api(2.0 到 2.2)的版本与 Tomcat 7 在依赖项(Parent聚甲醛)。没变。
- 我们已经从应用程序
web.xml
的 Tomcat 文件中复制了默认和 jsp servlet 映射配置web.xml
。没变。
- 我们已将 url 模式更改
/
为默认 servlet/*
的 tomcat文件中的内容,并且开始使用静态资源,但不适用于文件(Faces)。但正如 servlet 规范 (JSR-315) 中所述,它应该与. 无论哪种方式,此更改都破坏了所有上下文的 *.jsp 请求(¿?)。web.xml
*.jsp
*.xhtml
/
- 我们已经从上下文文件中删除了所有内容
servlet-mapping
,以查看是否存在任何冲突。没变。filter-mapping
web.xml
我们怀疑...
要么tomcatweb.xml
没有被读取,要么被覆盖,要么被某些上下文描述符破坏/
的url模式。*.jsp
有什么线索吗?
提前致谢。