我正在为我的应用程序使用Angularjs,Java。最初我使用tomcat来运行我的应用程序。当我运行我的项目时,它将打开URL
http://localhost:8080/projectname
所以我将我的基本标签和html5模式配置为
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('');
<base href="/projectname/">
将欢迎文件配置为web.xml中的main.html,我添加了代码
<welcome-file-list>
<welcome-file>main.html</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/</location>
</error-page>
使ui-router能够使用html5模式(在ui-router问题页面中提到)。
然后我将我的项目更改为google app engine标准java项目,当我运行我的项目时,它会以url打开
所以我将我的基本标签更改为
<base href="/">
这与main.html没有问题,但我的路由不起作用。当我使用$ state.go时它的工作。但在刷新或手动输入网址时,我收到404错误。我的控制台错误是
WARNING: No file found for: /url
我引用了很多博客,但仍然对配置
感到困惑我在web.xml文件中配置了spring
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
似乎它将所有url请求映射到spring,有没有办法解决这个问题?
答案 0 :(得分:1)
问题在于刷新页面,如果你打开基础并点击它将起作用的任何链接,你需要编写重写URL的代码
对于运行IIS的应用程序,我们需要添加:
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
See detail for IIS configuration
抱歉,我从未使用过tomcat