www.webdeveloper.com
Results 1 to 4 of 4

Thread: Need Help writing from Flash to JSP to Java

  1. #1
    Join Date
    Apr 2006
    Posts
    5

    Question Need Help writing from Flash to JSP to Java

    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

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,119
    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.
    Last edited by Khalid Ali; 05-16-2006 at 09:24 AM.
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Apr 2006
    Posts
    5

    note communicating with server

    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

  4. #4
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,119
    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.
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles