目前JavaFX相关的资料都是基本语法,以及界面相关。而JavaFX面向的是RIA,RIA就肯定需要和后台交互,个人研究了一下,遇到了不少问题,共享给大家 :D
首先先看看JavaFX的api,一眼就能看到javafx.io.http包,包里面有三个类,HttpHeaders,HttpRequest,HttpStatus三个类。具体用法,呵呵,看API吧。主要使用的就是HttpRequest类了。API里也有比较详细的例子。
这里有修改此例来实现Http的get和post提交,分别和后台交互。
先写个servlet
首先先看看JavaFX的api,一眼就能看到javafx.io.http包,包里面有三个类,HttpHeaders,HttpRequest,HttpStatus三个类。具体用法,呵呵,看API吧。主要使用的就是HttpRequest类了。API里也有比较详细的例子。
这里有修改此例来实现Http的get和post提交,分别和后台交互。
先写个servlet
public class MooServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
String name = request.getParameter("name");
PrintWriter writer = response.getWriter();