I am inspired from w3schools try it yourself editor. It is better to give an option to users to try themselves.
This below Try It Your Self editor was built upon HTML, JavaScript and Java. You can find the below diagram for program flow.

<textarea class="code_input" id="textareaCode" wrap="logical" rows="30" cols="50">
...
</textarea>

Form to Submit the code to Server :

Here the "target" attribute was specified as "view" so the output of this form will be displayed in "view" named iframe. 
<form style="margin:0px;display:none;" action="/TryItYourSelf" method="post" target="view" id="tryitform" name="tryitform" onsubmit="validateForm();">
        <input type="hidden" name="code" id="code" />
        <input type="hidden" id="bt" name="bt" />
</form>

iframe for displaying result :

<iframe id="iframeResult" class="result_output" frameborder="0" name="view" src="/angular-jquery/expressions_a.html"></iframe>

JavaScript for validating form :

function validateForm()
{
var code=document.getElementById("code").value;
if (code.length>8000)
    {
    document.getElementById("code").value="<h1>Error</h1>";
    }
}

JavaScript for submitting form  to server :

function submitTryit()
{
 var t=document.getElementById("textareaCode").value;
 t=encodeURI(t);
 document.getElementById("bt").value="1";
 document.getElementById("code").value=t;
 document.getElementById("tryitform").action="/TryItYourSelf?x=" + Math.random();
 validateForm();
 document.getElementById("tryitform").submit();
}

Java Servlet to read and write the code :

Here we have to set "X-XSS-Protection" and "Content-Security-Policy" as 0 unless it will throw security exceptions and script wont run.
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TryItYourSelf extends HttpServlet {
       
    public TryItYourSelf() {
        super();
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String code = request.getParameter("code");
        response.setHeader("X-XSS-Protection", "0");
        response.setHeader("Content-Security-Policy", "0");
        PrintWriter pw = response.getWriter();
        pw.print(java.net.URLDecoder.decode(code, "UTF-8"));
        pw.flush();
    }

}

9 comments:

  1. just what most individuals' desire. However, most of which have no idea of the inner thoughts and multi-step means of purchasing a fresh home vpn

    ReplyDelete
  2. My friend recommended this blog and he was totally right keep up the fantastic work! https://internetprivatsphare.ch/was-ist-vpn/

    ReplyDelete
  3. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. diebestenvpn

    ReplyDelete
  4. Conversion of PSD into website usually takes for professional about 8 hours for homepage and some more time for other additional pages. For novice in PSD to CSS conversion it may take several days to create a HTML.coding image example

    ReplyDelete
  5. This is very educational content and written well for a change. It's nice to see that some people still understand how to write a quality post.! https://vpnveteran.com/

    ReplyDelete
  6. Much appreciated such a great amount for this data. I need to tell you I agree on a few of the focuses you make here and others might require some further survey, however I can see your perspective. privatsphare

    ReplyDelete
  7. Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? lemigliori vpn

    ReplyDelete

Blogroll

Popular Posts