newbie2js
05-15-2006, 02:01 PM
I had someone create a quiz in flash. I need to send one variable (quiz score) to the sent to java to write the score to a text file.
Here is my code.
Flash:
var envio_lv:LoadVars = new LoadVars();
function send_data(per_val) {
envio_lv.PERCENTSCORE = per_val;
envio_lv.send("quiz_send.jsp",_blank,"POST");
quiz_send.jsp:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<TITLE>quiz_send.jsp</TITLE>
</HEAD>
<BODY>
<% String PERCENTSCORE = request.getParameter("PERCENTSCORE");%>
<form action="/WBTWeb/servlet/com.dcx.secaware.WriteText" method="post">
</BODY>
</HTML>
Java file:
package com.dcx.secaware;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class WriteText extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
static public String filelocations = "c:/quiz/scores.txt";
//static public String filelocations = "/clocal/tech/user/idsuser/scores.txt";
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
try {
String score = request.getParameter("PERCENTSCORE");
BufferedWriter out = new BufferedWriter(new FileWriter(filelocations,true));
out.write(",");
out.write(score);
out.close();
} catch (IOException e){
e.printStackTrace();
}
}
}
Please help I have been working on this for weeks and I needed to get it to work like yesterday.
If I test it in a form where I enter the variable in it writes to the file.
Thanks
Here is my code.
Flash:
var envio_lv:LoadVars = new LoadVars();
function send_data(per_val) {
envio_lv.PERCENTSCORE = per_val;
envio_lv.send("quiz_send.jsp",_blank,"POST");
quiz_send.jsp:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<TITLE>quiz_send.jsp</TITLE>
</HEAD>
<BODY>
<% String PERCENTSCORE = request.getParameter("PERCENTSCORE");%>
<form action="/WBTWeb/servlet/com.dcx.secaware.WriteText" method="post">
</BODY>
</HTML>
Java file:
package com.dcx.secaware;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class WriteText extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
static public String filelocations = "c:/quiz/scores.txt";
//static public String filelocations = "/clocal/tech/user/idsuser/scores.txt";
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
try {
String score = request.getParameter("PERCENTSCORE");
BufferedWriter out = new BufferedWriter(new FileWriter(filelocations,true));
out.write(",");
out.write(score);
out.close();
} catch (IOException e){
e.printStackTrace();
}
}
}
Please help I have been working on this for weeks and I needed to get it to work like yesterday.
If I test it in a form where I enter the variable in it writes to the file.
Thanks