sendto - How can I send a text information to a servlet that creates a text file containing it? -
i created ajax app should send text info tomcat server, , there should have servlet in theory should text , save in file.
i created app gets content of text area , transforms json , send tomcat server, there should have servlet receives , save json text file, i'm not sure on how install/deploy servlet in server, plus , don't know how make communicate ajax. can conduct me , me through it?
thanks in advance.
my "servlet"
package servletpackage; import java.io.filenotfoundexception; import java.io.printwriter; import java.io.unsupportedencodingexception; public class servlet { static string position = "that json info should here"; public static void main(string[] args) throws filenotfoundexception, unsupportedencodingexception { printwriter writer = new printwriter("positions.txt", "utf-8"); writer.println(position); writer.close(); } }
my app "it's more complicated this, easier comprehension of idea created example. that's why i'm talking json, though in example transforming text json doesn't make sense"
$(function() { alert("file has been succesfully sent"); var data = new formdata(); var cssdata = $("#custom-css-text").val(); data.append("custom_css", cssdata); $.ajax({ url: 'myserver', type: 'post', data: data, cache: false, datatype: 'json', processdata: false, contenttype: false, success: function(response) { alert("file has been succesfully sent"); }, error: function(jqxhr, textstatus, errorthrown) { alert('errors: ' + textstatus); } }); });
<!doctype html> <html> <head> <title>html5, css3 , javascript demo</title> <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> </head> <body> <textarea id="custom-css-text">testing</textarea> </body> </html>
Comments
Post a Comment