angular - 从 Angular 7 调用遗留代码 jsp/servlet 代码返回 302 错误
问题描述
我正在使用 jsp 和 servelts 将我们的遗留代码更新到 angular 7。但是,遗留代码的某些部分我仍然需要维护。因此,我必须对具有以下 Web 服务的 Web 服务进行一些调用。
@RequestMapping(value = "/mainpage", method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView portalMainPage(HttpServletRequest request, HttpServletResponse response) throws Exception {
/* Code here to do a few things */
return new ModelAndView(".company.portal.mainpage");
}
我尝试从角度调用它,但正如您所见,它返回一个模型和视图,并有自己的用于渲染的 jsp 页面。
我如何从角度调用它并让它呈现 jsp 页面?
我试图调用它,但我收到一条 HTTP 302 错误消息,它重定向到 index.html 页面,该页面是 angular 的欢迎页面。它无法呈现 jsp 页面。
我称之为直接来自浏览器的方式:https://company/portal/mainpage.do。完成此操作后,我检查了开发人员工具中的网络设置。它显示 302 消息,然后将其重定向到 index.html。
解决方案
所以我能够解决这个问题。问题是 xml 文件中没有视图解析器。
所以我在 xml 文件中添加了以下代码。添加后,问题解决了
<mvc:annotation-driven />
<mvc:default-servlet-handler/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.tiles2.TilesView</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/config/spring-tiles.xml</value>
<!-- <value>/WEB-INF/config/cwf/tiles-defs-cwf.xml</value> -->
</list>
</property>
</bean>
推荐阅读
- r - 在第一次出现模式正则表达式 gsub R 后删除所有内容
- docker - 使用 docker compose 为不同的 IP 地址缩放容器
- sqlite - 具有双主键的 SQLite3 数据显示不正确
- java - 使用 Geb 提取 Stackoverflow 问题计数器
- angular - 在异步函数中返回 Observable
- .net - 如何在 .NET MVC Core 中使用角色
- mysql - Laravel:如何在 MySql 数据库中存储印地语字符
- javascript - 在附加了语言环境的 javascript 中生成日期格式
- oracle - 如何关闭 docker 容器内的 oracle 数据库?
- python - TensorFlow 识别但不会使用我的 GPU