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