0

This is the jsp code that I'm working on. My aim is to create an online java compiler window which gets a java program and display its executed output. I need to get the program code from the text area named "program" and need to display the output in the text area named "output". Using a form and submitting it to servlet leads to refreshing the content.

How could I get the text from the text area and use it in my java function?

Or is there any other way to get the data and process it without submitting it to a servlet?

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Take Test Editor</title>
<%@ page import="com.lpat.util.CreateFile"%>
</head>
<body>
    <div style="float:left">
        <label>Write your code here</label>
    </div>
    <div style="float:right">
        File Name :
        <input type="text" name="file_name" id="file_name">.java
        <button onclick="save()">Save</button>
        <button onclick="run()">Run</button>
        <%!
            CreateFile file = new CreateFile();
            String fileName = request.getParameter("file_name");
            String code = request.getParameter("program");

            void save() {
                file.saveFile(fileName, code);
            }

            void run() {

            }
        %>
    </div>
    <textarea name="program"></textarea>
    <label> User Input </label>
    <textarea name="input"></textarea>
    <label> Output </label>
    <textarea name="output" readonly></textarea>
</body>
</html>

Why is request.getParameter("fileName"); and out.println(); works in the following code

<%
    String fileName = request.getParameter("file_name");
    String code = request.getParameter("program");
    out.println(fileName + ".java is saved.");
%>

but not working inside

<%!
    String fileName = request.getParameter("file_name");
    String code = request.getParameter("program");
    out.println(fileName + ".java is saved.");
%>

how to get the content and display a content inside

  • You must send to a servlet but do not have to refresh – mplungjan Apr 03 '17 at 07:46
  • sending a data from jsp to servlet will automatically lead to refreshing the content right? then i need to redirect to my jsp file again and it wont contain the previously entered data.. When I tried to send it to servlet this is how it happened – Azhagarasan Murali Apr 03 '17 at 07:50
  • 2
    No, Ajax doesn't have to refresh the whole page, just a part of it (but the trick is that you don't return your jsp page back to the client, instead you just return some content that has been changed and use javascript on the client to update a part of your page. – dsp_user Apr 03 '17 at 08:00

0 Answers0