Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1.  
  2.  
  3. <!doctype html>
  4. <html lang="en">
  5. <head>
  6. <meta charset="utf-8">
  7. <title>Tusky's code executor</title>
  8. <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  9. </head>
  10. <body>
  11. <h1>Write Your Java Code below</h1>
  12. <form action="/" id="searchForm">
  13. Class name: <input type=text name="classname" id="className"><br>
  14. <p><textarea name="textarea" id="textArea" rows="20" cols="100">
  15. </textarea>/></p>
  16. <input type="submit" value="RUN">
  17. </form>
  18. <!-- the result of the search will be rendered inside this div -->
  19. <div id="result"></div>
  20.  
  21. <script>
  22. // Attach a submit handler to the form
  23. $( "#searchForm" ).submit(function(event) {
  24. // Stop form from submitting normally
  25. event.preventDefault();
  26.  
  27. // Get some values from elements on the page:
  28. var $form = $( this ),
  29. code = $("#textArea").val(),
  30. classname= $("#className").val(),
  31. url = "http://localhost/OnlineCodeExecution/api/UserCodeService/code/output";
  32. // Send the data using post
  33. if(code&&classname)
  34. {
  35. $.ajax({
  36. url: "/OnlineCodeExecution/api/UserCodeService/code/output",
  37. dataType: 'text',
  38. contentType: "application/json;charset=utf-8",
  39. type: "POST",
  40. data: {ans : code, classn : classname}, // Trying to multiple parameters, not working
  41. }).done(function(data){console.log(data); // Response
  42. $( "#result" ).empty().append( data+"<br>")
  43. })
  44. .fail(function() { alert("error"); })
  45. .always(function() { alert("complete"); });
  46. }
  47. else
  48. {
  49. alert("please fill all the entries");
  50. }
  51. });
  52. </script>
  53. <div id = result style="width:50%"></div>
  54. </body>
  55. </html>
  56.  
  57. -----------------------------------------------------------------------------------------------------------------------------------
  58.  
  59. package server;
  60. import org.json.JSONException;
  61.  
  62.  
  63.  
  64. import javax.ws.rs.Consumes;
  65. import javax.ws.rs.POST;
  66. import javax.ws.rs.Path;
  67. import javax.ws.rs.core.MediaType;
  68. import javax.ws.rs.core.Response;
  69.  
  70. /**
  71. *
  72. * @author tushar
  73. *
  74. */
  75.  
  76. @Path("UserCodeService")
  77. public class UserCodeInfo {
  78.  
  79. @POST
  80. @Path("/code/output")
  81. @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
  82. /*
  83. *Trying to a ccept multiple parameters
  84. */
  85. public Response results(String ans, String classn) throws JSONException{
  86. String result = "client code is "+ans;
  87. String class_name = "class name is "+classn; //classn variable receiving null always
  88. //UserCodeRequest u= new UserCodeRequest(ans);
  89. System.out.println(result);
  90. System.out.println(class_name);
  91. result = processStringInput(ans);
  92. System.out.println("result is "+result);
  93. return Response.status(200).entity(result).build();
  94. }
  95.  
  96. private String processStringInput(String ans) throws JSONException {
  97. String result = UserCodeProcessor.processCode(ans);
  98. System.out.println(result);
  99. return result;
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement