dongnaigu2052 2017-04-13 06:12
浏览 70
已采纳

两个html为一个结果页面形成一个提交按钮

I have two forms the first one is full of different networks (ex: A, B, C) and the second form is full of different java functions (ex: average.java, length.java, edges.java) that take the text file that represents the network (ex: networkA.txt is the text file for network A) and run the code. I have this part figured out. Where I am running into a problem is that I want to cut down on the amount of pages that I need to be using for efficiency purposes. I have 26 different networks and I dont want to make that mean that I have 50 different network form files and consequently 26 different function form files.

Ideally I want network.php (where user can pick from 26 different networks ---> A, B, C...Z) with radio buttons. And then I want the user to be able to submit the form. The next page that pops up function.php I would want to have the function form on there with radio buttons (ex: average, length, amount. Then with this submit button (for function.php), I want to take the two forms and with the selected choices (Ex: network: A function: edges) run that network txt file through the java code for that function and spit out the result in a results.php page.

So to clarify my question I am wondering if there is a way to keep the choice from networks stored when i go from network.php to function.php to then run through the java code and spit out in results.php. Ive been reading that there is a show./hide function in javascript that does this however I cannot find any good tutorial or web page addressing how to do this in the context that I am trying to do it. Any help, hints, pointers, or example code is welcome and much appreciated.

NetworkA.txt
0 1 0 2 0 3 1 2 2 3 3 4 4 5 5 6 5 7 6 7



Edges.java

import java.util.*;
import java.io.*;

class Edges{

    public static void main(String[] args){

    try{

        FileReader fr = new FileReader(args[0]);
        BufferedReader br = new BufferedReader(fr);

        String line = null;

        int numEdges = 0;

        while (  (line = br.readLine() ) != null){
            System.out.println(line);
            numEdges++;
        }

        System.out.println("Total # Edges: "+numEdges);


    }
    catch(Exception e){e.printStackTrace();}

    }

}



RunCode.php ---> This is what i use to compile java code in my php page

$PATH="C:\Program Files\Java\jdk1.8.0_101\bin";
      echo exec("javac Edges.java 2>&1");//shows # of errors
      echo "<br />";
      echo exec("java Edges networkA.txt 2>&1");//this line executes it
      echo "<br />";
      echo shell_exec("javac Edges.java 2>&1 ");//compiles it



networkA.php ---> networkA complies the code and gives me a result of in this case = 10 edges

<header>

    <div class="nav">

        <ul>
            <li><a href="logout.php">Logout</a></li>
        </ul>

    </div>

    <div class="form">
      <?php


      $PATH="C:\Program Files\Java\jdk1.8.0_101\bin";
      echo exec("javac ListEdges.java 2>&1");//shows # of errors
      echo "<br />";
      echo exec("java ListEdges networkA.txt 2>&1");//this line executes it
      echo "<br />";
      echo shell_exec("javac ListEdges.java 2>&1 ");//compiles it

      ?>
      <a class="tryagain" href='index.php' target="_blank">Try Again?</a></p>
    </div>

</header>

<footer>

    <div class="footer">
      by Jason Bruno

    </div>
</footer>

  • 写回答

1条回答 默认 最新

  • duangu1868 2017-04-16 23:14
    关注

    Sounds like you want to use a form POST action to submit your choices to network.php:

    <form action="network.php" method="post">
    <label><input type="radio" name="networkChoice" value="A"> Network A</label>
    <label><input type="radio" name="networkChoice" value="B"> Network B</label>
    ...put more options here...
    <input type="submit">
    </form>
    

    Then you can get the data you posted back out in PHP using $_POST[]

    $network = $_POST["networkChoice"];
    ...do stuff...
    

    More POST/GET examples: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_and_retrieving_form_data#The_POST_method

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示