JAVA将字符串上传到服务器

时间:2014-11-30 00:47:38

标签: java ftp

我想在java中将字符串上传到服务器。我不想只上传一个我想上传字符串的文件

String toupload = "Cheese"; Upload(toupload);
像这样

1 个答案:

答案 0 :(得分:0)

您可以使用 POST 方法和 GET 方法上传它:     如果您使用GET方法:您在网址中传递字符串。

例如: localhost:8080 / yourwebproject / yourservlet?nameofyourstring = itsvalue

然后在你的servlet中你可以做类似的事情:

    public myServlet extends HttpServlet(HttpServletRequest request, HttpServletResponse response)
       public myServlet() {
            super();
        }
       /*This method will be called by your web-container if you used the get method..*/
       protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/html");
        //here we go
        String str = request.getParameter("nameOfyourString");
       }`
}

If you use the POST method, you have to implement the doPost with same logic..