Click to See Complete Forum and Search --> : Need Help writing from Flash to JSP to Java


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

Khalid Ali
05-16-2006, 12:00 AM
u are sending the result from flash to jsp. Then u are retrieving the value in the jsp, however after that u do not do anything, what u need to do is forward that variable to the servlet either directly or submit the jsp page again by adding html submit button to it.

newbie2js
05-16-2006, 08:25 AM
Thanks Khalid Ali

I tried sending it directly from flash but I can't tell if it's working. In Websphere under the servers, I'm not getting any indication that it is working.
Flash:
var envio_lv:LoadVars = new LoadVars();
function send_data(per_val) {
envio_lv.PERCENTSCORE = per_val;
envio_lv.send("/servlet/com.dcm.secaware.WriteText",_blank,"POST");// I put the address of the servlet and it's not working.
I would prefer to go this route anyway. Is there any reasons why it won't work?

Angela

Khalid Ali
05-16-2006, 10:26 AM
I don't know how flash works or how it will send requests to a server. For that you probably are better off if you post your question in the graphics section, some one there might know about it.