Reputation: 1
I am developiong an application in angular 7. its being built to update a legacy application that also supports jsp pages. Currently when i try to call the index.jsp page it automatically redirects to index.html. I am not able to call any jsp pages. They are all under the same base href. I need to use these jsp pages for some parts. The application is deployed on websphere.
The context-url is portal
<?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>
I have index.jsp and index.html both. The welcome file list in web.xml is pointing to index.html In web.xml i have multiple url patterns
<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>
for the index.html page i have
i also configured app routing in app-routing-module.ts
const routes: Routes = [
{ path: 'manage.do', redirectTo : '/index.jsp', pathMatch : 'full'},
];
Whenever i call the url https://localhost:9443/portal/ or https://localhost:9443/portal/index.html , it goes to index.html
But when i call https://localhost:9443/portal/index.jsp or https://localhost:9443/portal/manage.do, it still always redirects to index.html.
But i need it to call the jsp page and redirect to the legacy code, anyone has any suggestions
The JSP page calls manage.do
@RequestMapping(value = "/manage", method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView portalMainPage(HttpServletRequest request, HttpServletResponse response) throws Exception {
as you can see it has return type as modelandview and not a list which can be rednered by angular.
It has its own jsp pages and its own view. Is there any way to redirect within the same ear file to the jsp page ?
Upvotes: 0
Views: 2725
Reputation: 688
first of be aware of this that redirectTo : '/index.jsp'
doesn't let users navigate to index.jsp
page, but it means redirect to '/index.jsp' path defined in the 'routes' array.
I mean redirectTo works like this:
const routes: Routes = [
{ path: 'manage.do', redirectTo : 'index', pathMatch : 'full'},
{ path: 'index', component: MyIndexComponent},
];
It means, redirectTo works fine if there is some path item in 'routes' array.
Now, as for the solution, I recommend you to navigate users to index.jsp page in .ts
file by writing JavaScript code, as follows:
const routes: Routes = [
{ path: 'manage.do', redirectTo : 'index-jsp', pathMatch : 'full'},
{ path: 'index-jsp', component: MyIndexJspComponent},
];
and create a component as MyIndexJspComponent like this:
import { Component, OnInit } from '@angular/core';
@Component({
templateUrl: '<div></div>',
styleUrls: [],
})
export class MyIndexJspComponent implements OnInit {
constructor() { }
ngOnInit() {
window.location.href = "/index.jsp";
}
}
Now this is fit for an Angular project architecture and all correct for you. Now users can call 'manage.do' anywhere, and goes to index.jsp.
P.S.: I am not sure it all works fine in development mode. But hoping works with prod mode.
Upvotes: 0