用JSP,表单提交后,三个int参数和一个boolean初始化给一个JavaBean,JavaBean提供一个返回int[]的方法(属性),排序后产生升序或降序表示int[]。具体JSP和JavaBean还是自己写吧,练练手。

解决方案 »

  1.   

    为了第五条内裤,我来写吧:
    JSP Source:
    <%@ page contentType="text/html; charset=GBK" %>
    <html>
    <head>
    <title>
    jsp1
    </title>
    </head>
    <jsp:useBean id="jsp1BeanId" scope="request" class="tour.Jsp1Bean" />
    <jsp:setProperty name="jsp1BeanId" property="*" />
    <body bgcolor="#ffffff">
    <h1>
    JBuilder Generated JSP
    </h1>
    <form method="post">
    <br>
      Enter new value #1  :  <input name="sample1"><br>
      Enter new value #2  :  <input name="sample2"><br>
      Enter new value #3  :  <input name="sample3"><br>
      Sort : <input type="radio" name="sort" value="a" checked="checked"/>升&nbsp;&nbsp;<input type="radio" name="sort" value="d"/>降
    <br><br>
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" value="Reset">
    <br>
    Value of Bean property #1 is :<jsp:getProperty name="jsp1BeanId" property="sample1" /><br>
    Value of Bean property #2 is :<jsp:getProperty name="jsp1BeanId" property="sample2" /><br>
    Value of Bean property #3 is :<jsp:getProperty name="jsp1BeanId" property="sample3" /><br>
    Sort :<jsp:getProperty name="jsp1BeanId" property="sortedString" /><br>
    </form>
    </body>
    </html>
    //-------------------------------------------------
    Bean Source:
    package tour;
    /**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class Jsp1Bean {
      private int sample1=0;
      private int sample2=0;
      private int sample3=0;  int[] numbers=new int[3];
      private String sort="a";
      private String sortedString="";  public int getSample1() {
        return sample1;
      }
      public void setSample1(int sample1) {
        numbers[0]=sample1;
        this.sample1 = sample1;
      }
      public int getSample2() {
        return sample2;
      }
      public void setSample2(int sample2) {
        numbers[1]=sample2;
        this.sample2 = sample2;
      }
      public int getSample3() {
        return sample3;
      }
      public void setSample3(int sample3) {
        numbers[2]=sample3;
        this.sample3 = sample3;
      }  private void sort(){
        int temp=0;
        for (int i=0; i<numbers.length-1 ; i++ ) {
          if (numbers[i]>numbers[i+1]) {
            temp=numbers[i+1];
            numbers[i+1]=numbers[i];
            numbers[i]=temp;
          }
        }
      }
      
      public String getSortedString(){
        sort();
        if (getSort().equals("d")) {
          int temp=numbers[2];
          numbers[2]=numbers[0];
          numbers[0]=temp;
        }
        for (int i = 0; i < numbers.length; i++) {
          sortedString+=","+numbers[i];
        }
        sortedString=sortedString.substring(1);
        return sortedString;
      }
      
      public String getSort() {
        return sort;
      }
      public void setSort(String sort) {
        this.sort = sort;
      }
    }
    同志,要给分啊