Search code examples
angularjboss

why page show 404 when manually refreshing URL in browser angular 7 on JBOSS server?


When I execute my application in browser it works perfectly as expected but when I press F5 or refresh page then it shows me 404 server error.

I am searching for a long time for this issue and I find lots of answers but none of them worked for me.

I have implemented HashLocationStrategy. Here is below code:

App.module.ts

import {LocationStrategy, HashLocationStrategy} from '@angular/common';

and

imports: [
NgbModule.forRoot()],
providers:[{provide: LocationStrategy, useClass: HashLocationStrategy}]

Routing.module.ts (Create separated file for Routing)

@NgModule({
imports:[
    RouterModule.forRoot(appRoutes, { useHash: true })
],
exports:[RouterModule]
})

Note 1 : Instead of marking "Negative" I request you to please ask me anything if you need more clarification.

Note 2 : I am new to this and I don't have knowledge of server side or JAVA language


Solution

  • I got solution of my Question.

    Below code I added in web.xml file only and works for me.

    <servlet>
    <servlet-name>page</servlet-name>
    <jsp-file>/WebClientV2/index.html</jsp-file>
    </servlet>
    <servlet-mapping>
    <servlet-name>page</servlet-name>
    <url-pattern>/WebClientV2</url-pattern>
    <url-pattern>/WebClientV2/login</url-pattern>
    <url-pattern>/WebClientV2/messages</url-pattern>
    <url-pattern>/WebClientV2/contacts</url-pattern>
    <url-pattern>/WebClientV2/staff-assignment</url-pattern>
    <url-pattern>/WebClientV2/nurse-rounding</url-pattern>
    <url-pattern>/WebClientV2/myPatient</url-pattern>
    </servlet-mapping>