Angular & Spring:如何加载外部页面,而不暴露URL?
创始人
2024-10-14 11:31:29
0

在Angular和Spring中加载外部页面而不暴露URL可以通过以下步骤实现:

  1. 在Angular中创建一个组件,用于加载外部页面。
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';

@Component({
  selector: 'app-external-page',
  template: '
', styleUrls: ['./external-page.component.css'] }) export class ExternalPageComponent implements OnInit { @ViewChild('externalPage', { static: true }) externalPage: ElementRef; ngOnInit() { const iframe = document.createElement('iframe'); iframe.src = 'http://example.com/external-page'; // 替换为要加载的外部页面的URL iframe.setAttribute('sandbox', 'allow-same-origin allow-scripts'); iframe.style.width = '100%'; iframe.style.height = '100%'; this.externalPage.nativeElement.appendChild(iframe); } }
  1. 在Spring中创建一个controller,用于返回外部页面的内容。
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class ExternalPageController {

  @RequestMapping("/external-page")
  public ModelAndView redirectToExternalPage() {
    return new ModelAndView("redirect:http://example.com/external-page"); // 替换为要加载的外部页面的URL
  }

  @GetMapping("/external-page-content")
  @ResponseBody
  public String getExternalPageContent() {
    // 通过HTTP请求获取外部页面的内容
    // 返回外部页面的内容
    return "

Hello, External Page!

"; } }
  1. 在Spring的配置文件中配置视图解析器。

  
  

  1. 在Angular的路由配置中将外部页面组件添加为一个路由。
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ExternalPageComponent } from './external-page/external-page.component';

const routes: Routes = [
  { path: 'external-page', component: ExternalPageComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

通过以上步骤,你可以在Angular中创建一个组件来加载外部页面,并在Spring中通过控制器返回外部页面的内容。这样,你就能在不暴露URL的情况下加载外部页面。

相关内容

热门资讯

推荐十款!大菠萝免费辅助,拱趴... 推荐十款!大菠萝免费辅助,拱趴大菠萝机器人,线上教程(有挂教程),支持语音通讯、好友开房及战队组建,...
玩家必用!约局吧如何查看是否有... 1、玩家必用!约局吧如何查看是否有挂,wepoker怎么买辅助,安装教程(有挂透明)。2、约局吧如何...
总算了解!epoker免费透视... 总算了解!epoker免费透视脚本,wepoker网页版透视方法,软件教程(有挂软件);支持2-10...
实测交流!wepoker的辅助... 实测交流!wepoker的辅助器,uupoker透视,普及教程(有挂软件);wepoker的辅助器软...
我来教大家!aa poker辅... 我来教大家!aa poker辅助,拱趴大菠萝作弊方法,新2025教程(有挂技巧);1分钟了解详细教程...
大家学习交流!wepoker辅... 大家学习交流!wepoker辅助真的假的,aapoker怎么设置提高好牌几率,必备教程(有挂教程)这...
关于!wepoker私人局辅助... 1、关于!wepoker私人局辅助,红龙poker辅助平台,安装教程(有挂攻略);详细教程。2、红龙...
推荐十款!pokemmo辅助官... 推荐十款!pokemmo辅助官网,约局吧辅助器,2025新版技巧(有挂教程);大神普及一款德州ai内...
传递经验!wepoker透视脚... 此外,数据分析德州(wepoker透视脚本免费app)辅助神器app还具备辅助透视行为开挂功能,通过...
一分钟了解!wepoker俱乐... 一分钟了解!wepoker俱乐部辅助,wepoker透视脚本免费app,2025新版教程(有挂神器)...