java - 将 jsp 页面移至 Angular 7

标签 java angular jsp spring-rest

我目前正在开发一个 Angular 项目,将我们现有的应用程序从 jsp 更新到 Angular 7。但是,有一些 jsp 页面我还无法完全转换为 html,因为它们需要遗留支持。

所以我需要知道如何将它们移动到 Angular 。我的想法是将 jsp 页面及其所有 css 复制到 Angular 组件。

The jsp code is something like below
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ include file="/WEB-INF/jsp/cwf/common/include.jsp"%>
<link
    href="<%=request.getContextPath()%>/static/css/insurance/insureServ.css"
    rel="stylesheet" type="text/css" />
<%-- START CONTAINER --%>
<div id="container">

    <%-- START HEADER --%>
    <div id="header">

        <div class="headerLogoProd">&nbsp;</div>
        <%-- ///Use  class="headerLogoPSE" or class="headerLogoProd" depending on desired logo /// --%>
        <div class="floatleft">
            Welcome,
            <c:out default="Guest" value="${name}" />
        </div>
        <div
            style="border-style: none; float: left; font-size: 1.5em; font-family: sans-serif; color: #FF800D">PRODUCTION</div>
        <div class="floatright">
            <a target="_blank"
                href="http://test.net">Contact
                Us</a> | <a href="mailto:insurance@tst.net">Feedback</a> | <a
                target="_blank" href="http://fakeurl.net">ABDHome</a>
        </div>

    <%-- START Icon Elements --%>
        <c:forEach items="${userTamRoles}" var="userTamRole">
            <c:if test="${userTamRole eq 'ATH'}">
                <div class="icon_element"
                    onMouseOver="this.className='icon_elementHover'"
                    onMouseOut="this.className='icon_element'">
                    <a target="_blank" href="fake.do"><img
                        src="static/images/ins/asdf.gif" alt=""
                        width="90" height="70" vspace="5" align="left"><br />
                        <h3>Inquiry</h3> View transactions for the
                         Transfer Service.</a>
                </div>
            </c:if>
///More html code similar to above here


</div>
<%-- END CONTAINER --%>
<script type="text/javascript">
var url = window.location.href;
var n = url.indexOf("https://pott");
if(n > -1) {
    document.getElementById("ddd").style.display = "none";
    } 
</script>

现在使用spring的当前代码具有如下的web服务

@RequestMapping(value = "/inland", method = RequestMethod.GET)
public ModelAndView insuranceLandingpage(HttpServletRequest request) throws Exception {

    // get the user name and set it in the session, we will use this in the jsp
    String name = cuoUser.getUserFirstName() + " " + cuoUser.getUserLastName();
    request.getSession().setAttribute("name", name);

    // get entitled products /Roles from TAM
    List<String> user= this.headerUtil.getRolesFromReqHeader(request, userId);
    request.setAttribute("userTamRoles", user);
    return new ModelAndView(".abc.portal.insurance");
}

并且 servlet.xml 已定义映射

**

<definition name=".abc.portal.insurance"
        template="/WEB-INF/jsp/tiles/insurance/inlanding.jsp">
        <put-attribute name="body"
            value="/WEB-INF/jsp/tiles/insurance/inlanding.jsp" />

**

现在,使用 Angular 我无法使用模型和 View ,因此我必须重构 Web 服务以返回 json 对象。但是,如何渲染jsp页面呢?我可以复制整个jsp页面并将其粘贴到 Angular 组件中。但我如何呈现请求参数?例如,我如何呈现这个 <c:forEach items="${userTamRoles}" var="userTamRole"> or <c:out default="Guest" value="${name}" />进入 Angular 组件?它会将其识别为 jsp 语法吗?

最佳答案

我自己解决了这个问题。我没有在 Angular 上重新渲染 jsp 页面,而是在 servlet xml 文件中添加了一个 View 解析器。

<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>

关于java - 将 jsp 页面移至 Angular 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61352023/

相关文章:

java - lwjgl双击鼠标事件

angular - 简单的 ng-content 在 Angular 2 中不起作用

java - 在刷新之前,Struts2 session 数据在 JSP 中不可用

javascript - AngularJS中我的jsp中其他 Controller 的可访问性

java - 对自定义对象映射进行排序

java - 在 Rhino 中访问 java map 和列表作为 JavaScript 对象

selenium - Protractor : Error while waiting for Protractor to sync with the page: "Could not find testability for element."

node.js - 添加到主屏幕不会出现在我的 Angular 应用程序中

html - 如何设置自定义正文标签

java - 将自定义方法添加到系统类