我想使用socket从Android客户端向Java服务器发送2个对象(因为我正在开发远程PC).
AndroidClient.java
public class MainActivity extends Activity{
Socket client;
ObjectOutputStream oos;
OutputStream os;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SendObj so=new SendObj();
so.execute();
}
class SendObj extends AsyncTask<Void, Void, Void>{
@Override
protected Void doInBackground(Void... arg0) {
try {
client=new Socket("192.168.237.1",6566);
os=client.getOutputStream();
oos=new ObjectOutputStream(os);
Serializer ma=new Serializer(2, "Helllo");
Log.i("Serial",""+ma.name);
oos.writeObject(ma);
oos.writeObject(new String("Another Object from Client"));
oos.close();
os.close();
client.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
@Override
public boolean onCreateOptionsMenu(Menu …
Run Code Online (Sandbox Code Playgroud) 我正在构建一个使用 mysql 作为后端的简单网站。我有一个表单,它有 2 个按钮,其中一个从 db 搜索数据并使用 Ajax 填充页面,另一个按钮将新值更新为 db。现在我的问题是我不能将两个按钮都用作“提交”按钮。
Ajax 方法和 Html 格式:
<script type="text/javascript">
$(document).ready(function(){
$(document).on('submit', '#update-form', function(){
var data = $(this).serialize();
$.ajax({
type : 'POST',
url : 'search.php',
data : data,
success : function(data){
$(".display").html(data);
}
});
return false;
});
});
</script>
<body>
<div id="update" class="tab-pane fade">
<form id="update-form" role="form" class="container" method="post" action="search.php">
<h3>Update details</h3>
<table class="display">
<tr class="space">
<td><label>File Number:</label></td>
<td><input type="text" class="form-control" name="filenum" required></td>
</tr>
</table>
<button type="submit" class="btn btn-default text-center" name="search_btn" >Search</button>
<button type="submit" …
Run Code Online (Sandbox Code Playgroud) 我正在一个 Angular4 + PHP 网站上工作,在那里我使用 Promise 向服务器发送 HTTP 请求,因为我希望我的应用程序根据服务器的响应执行路由。我想访问 then() 中的一个类变量,但它会引发undefined()
错误。
这是我的代码:
status = false;
checkUser(): Promise<any>{
// .....
return this.http
.get('http://localhost:8000/api/user', this.options)
.toPromise()
.then(this.extractData)
.catch(this.handleError);
}
private extractData(res: any) {
data = res.json();
this.status = data.status; // here it throws error undefined
return this.status;
}
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以实现这一点?
我正在尝试在 Material-UI 数据网格中实现快速过滤/搜索选项。截至目前,数据网格没有搜索选项。我正在使用Material-UI-Search-Bar库来添加搜索字段和功能。我在自定义工具栏中有这个,但不幸的是这不起作用,因为它与状态有关。我无法聚焦文本字段。下面是我的代码
...
const requestSearch = (searchedVal: string) => {
const filteredRows = tableData.filter((o: any) => {
return Object.keys(o).some((k: any) => {
return o[k].toString().toLowerCase().indexOf(searchedVal.toLowerCase()) != -1;
})
});
console.log(filteredRows);
// setTableData(filteredRows);
};
const cancelSearch = () => {
setSearchText("");
requestSearch(searchText);
};
const CustomToolbar = () => {
<div className='p-6'>
<div> ... </div>
<SearchBar
value={searchText}
onChange={(searchVal: string) => requestSearch(searchVal)}
onCancelSearch={() => cancelSearch()}
/>
</div>
}
...
return (
<div ... >
<div style={{ height: 500, width: '100%', backgroundColor: …
Run Code Online (Sandbox Code Playgroud) 我的部分代码就在这里!
bufferedReader=new BufferedReader (inputstreamreader);
message=bufferedReader.readLine ();// ex: message has (1,-3)
String[] msg=message.split (",") //I use comma (,) as deliminator
int x=Integer.parseInt (msg [0]);
int y=Integer.parseInt (msg [1]);
Run Code Online (Sandbox Code Playgroud)
这清楚地解析但问题是它失去了负号.那就是"消息"包含(1,-3).请帮助我解析而不会失去-ve标志.
我使用 Laravel 作为我的 ionic 应用程序的后端,并使用 Laravel Passport 进行身份验证。当我尝试调用createToken()
它Auth
时,Call to undefined method
登录.ts:
login(event){
let dataJSON;
let formData = new FormData();
formData.append('email',event.target[0].value)
formData.append('password',event.target[1].value)
this.http.post(ENV.BASE_URL+'/auth', formData)
.subscribe((data) => {
console.log(data);
dataJSON = data;
}, (error) => {
console.log("Error!", error);
});
return false;
}
Run Code Online (Sandbox Code Playgroud)
用户控制器.php:
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Carbon\Carbon;
use App\User;
class UserController extends Controller{
public function auth(Request $request){
$params = $request->only('email', 'password');
$username = $params['email'];
$password = $params['password'];
if(\Auth::attempt(['email' => $username, …
Run Code Online (Sandbox Code Playgroud) 我现在面临一个奇怪的错误在我的角4 HTML模板,我想切换之类的<i>
标签,但只有一个类显示出来,而不是其他.这是我的代码;
<i [ngClass]="{'fa fa-eye': visible, 'fa fa-eye-slash': !visible}" aria-hidden="true" (click) = "toggle(pass)"></i>
Run Code Online (Sandbox Code Playgroud)
TS:
visible = false;
toggle(event){
this.visible = !this.visible;
}
Run Code Online (Sandbox Code Playgroud)
当我检查我的应用程序时,第一个图标显示,即默认打开fa fa-eye-slash
,但当我点击它时,它只显示框.
编辑:
尝试使用FA的不同图标,但没有任何显示.