2
我想用dart創建Web應用程序。所有的 首先出現的是HTML:更改Dart嵌入式Web服務器端口
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dart</title>
<link rel="stylesheet" href="dart.css">
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="application/dart" src="dart.dart"></script>
<script src="packages/browser/dart.js"></script>
</head>
<body>
<h1>Dart</h1>
<p>Hello world from Dart!</p>
<div id="sample_container_id">
<table id="table">
<tr>
<td>Benutzername:</td>
<td><input type="text" id="inputuser" maxlength="40"></td>
</tr>
<tr>
<td>Passwort:</td>
<td><input type="password" id="inputpass" maxlength="40"></td>
</tr>
<tr>
<td><button id="button"></button></td>
</tr>
</table>
</div>
</body>
</html>
在我的鏢文件我想連接到一個servlet,它運行在本地GlassFish服務器
鏢文件看起來像這樣的:
import 'dart:html';
final TableElement table = querySelector('#table');
final DivElement main_div = querySelector('#sample_container_id');
void main() {
TextInputElement user = querySelector('#inputuser');
PasswordInputElement password = querySelector('#inputpass');
ButtonElement button = querySelector('#button');
button.text = 'Send';
button.onClick.listen((e) => checkUser(user, password));
}
void checkUser(TextInputElement user, PasswordInputElement password)
{
var url = 'http://localhost:8080/dartTestServlet';
HttpRequest request = new HttpRequest();
request.open("POST", url);
request.onLoadEnd.listen((e) => onUserChecked(request.response.toString()));
String jsonData = '{"user":"' + user.value + '", "password":"' + password.value + '"}';
request.send(jsonData);
}
如果鏢連接到我得到這個錯誤消息的服務器:
Failed to load resource: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:3030' is therefore not allowed access. http://localhost:8080/dartTestServlet
我知道問題是相同的原產地政策,但我不知道如何解決它。
我正在使用服務器的eclipse實例和客戶端的Dart Editor實例。如何將Dart編輯器中的嵌入式Web服務器的端口更改爲8080?
我應該修復這個問題嗎?
Thanx尋求幫助。
這不能解決問題,因爲兩臺服務器不能使用相同的端口。您必須通過GlassFish服務器提供dart頁面,或使用CORS。 – MarioP
Thx。 我通過Glassfish提供該頁面。這解決了CORS「問題」。 – sylo