我正在 Angular 7 中开发一个应用程序。它的构建是为了更新也支持 jsp 页面的遗留应用程序。目前,当我尝试调用index.jsp页面时,它会自动重定向到index.html。我无法调用任何 jsp 页面。它们都位于相同的基本 href 下。我需要在某些部分使用这些 jsp 页面。 该应用程序部署在 websphere 上。
上下文 URL 是门户
<?xml version="1.0" encoding="UTF-8"?>
<web-ext
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://websphere.ibm.com/xml/ns/javaee"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_1.xsd" version="1.1">
<reload-interval value="3"/>
<context-root uri="portal" />
<enable-directory-browsing value="false"/>
<enable-file-serving value="true"/>
<enable-reloading value="true"/>
<enable-serving-servlets-by-class-name value="false"/>
</web-ext>
我有index.jsp和index.html。 web.xml中的欢迎文件列表指向index.html 在 web.xml 中我有多个 url 模式
<web-resource-collection>
<web-resource-name>action</web-resource-name>
<description />
<url-pattern>/manage.do</url-pattern>
<url-pattern>/save.do</url-pattern>
<url-pattern>/legacy.do</url-pattern>
<url-pattern>/acts.do</url-pattern>
</web-resource-collection>
对于我的index.html页面
我还在 app-routing-module.ts 中配置了应用路由
const routes: Routes = [
{ path: 'manage.do', redirectTo : '/index.jsp', pathMatch : 'full'},
];
每当我调用网址https://localhost:9443/portal/时或https://localhost:9443/portal/index.html , 它转到index.html
但是当我打电话https://localhost:9443/portal/index.jsp时或https://localhost:9443/portal/manage.do , 它仍然总是重定向到index.html。
但是我需要它来调用jsp页面并重定向到遗留代码,任何人都有任何建议
JSP页面调用manage.do
@RequestMapping(value = "/manage", method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView portalMainPage(HttpServletRequest request, HttpServletResponse response) throws Exception {
如您所见,它的返回类型为 modelandview,而不是可以通过 Angular 渲染的列表。
它有自己的jsp页面和自己的 View 。有没有办法在同一个ear文件中重定向到jsp页面?
最佳答案
首先要注意 redirectTo : '/index.jsp'
不允许用户导航到 index.jsp
页面,但这意味着重定向到“routes”数组中定义的“/index.jsp”路径。
我的意思是redirectTo 的工作原理如下:
const routes: Routes = [
{ path: 'manage.do', redirectTo : 'index', pathMatch : 'full'},
{ path: 'index', component: MyIndexComponent},
];
这意味着,如果“routes”数组中有某些路径项,redirectTo 就可以正常工作。
现在,对于解决方案,我建议您通过编写JavaScript代码将用户导航到.ts
文件中的index.jsp页面,如下所示:
const routes: Routes = [
{ path: 'manage.do', redirectTo : 'index-jsp', pathMatch : 'full'},
{ path: 'index-jsp', component: MyIndexJspComponent},
];
并创建一个组件作为 MyIndexJspComponent,如下所示:
import { Component, OnInit } from '@angular/core';
@Component({
templateUrl: '<div></div>',
styleUrls: [],
})
export class MyIndexJspComponent implements OnInit {
constructor() { }
ngOnInit() {
window.location.href = "/index.jsp";
}
}
现在这适合 Angular 项目架构,并且对您来说都是正确的。现在用户可以在任何地方调用“manage.do”,然后转到index.jsp。
P.S.:我不确定它在开发模式下是否一切正常。但希望能在产品模式下工作。
关于java - Angular 7 - 从 Angular 重定向到 jsp 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61255672/