Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Tusky's code executor</title>
- <script src="//code.jquery.com/jquery-1.10.2.js"></script>
- </head>
- <body>
- <h1>Write Your Java Code below</h1>
- <form action="/" id="searchForm">
- Class name: <input type=text name="classname" id="className"><br>
- <p><textarea name="textarea" id="textArea" rows="20" cols="100">
- </textarea>/></p>
- <input type="submit" value="RUN">
- </form>
- <!-- the result of the search will be rendered inside this div -->
- <div id="result"></div>
- <script>
- // Attach a submit handler to the form
- $( "#searchForm" ).submit(function(event) {
- // Stop form from submitting normally
- event.preventDefault();
- // Get some values from elements on the page:
- var $form = $( this ),
- code = $("#textArea").val(),
- classname= $("#className").val(),
- url = "http://localhost/OnlineCodeExecution/api/UserCodeService/code/output";
- // Send the data using post
- if(code&&classname)
- {
- $.ajax({
- url: "/OnlineCodeExecution/api/UserCodeService/code/output",
- dataType: 'text',
- contentType: "application/json;charset=utf-8",
- type: "POST",
- data: {ans : code, classn : classname}, // Trying to multiple parameters, not working
- }).done(function(data){console.log(data); // Response
- $( "#result" ).empty().append( data+"<br>")
- })
- .fail(function() { alert("error"); })
- .always(function() { alert("complete"); });
- }
- else
- {
- alert("please fill all the entries");
- }
- });
- </script>
- <div id = result style="width:50%"></div>
- </body>
- </html>
- -----------------------------------------------------------------------------------------------------------------------------------
- package server;
- import org.json.JSONException;
- import javax.ws.rs.Consumes;
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import javax.ws.rs.core.MediaType;
- import javax.ws.rs.core.Response;
- /**
- *
- * @author tushar
- *
- */
- @Path("UserCodeService")
- public class UserCodeInfo {
- @POST
- @Path("/code/output")
- @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON})
- /*
- *Trying to a ccept multiple parameters
- */
- public Response results(String ans, String classn) throws JSONException{
- String result = "client code is "+ans;
- String class_name = "class name is "+classn; //classn variable receiving null always
- //UserCodeRequest u= new UserCodeRequest(ans);
- System.out.println(result);
- System.out.println(class_name);
- result = processStringInput(ans);
- System.out.println("result is "+result);
- return Response.status(200).entity(result).build();
- }
- private String processStringInput(String ans) throws JSONException {
- String result = UserCodeProcessor.processCode(ans);
- System.out.println(result);
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement