简体   繁体   English

如何编写 jsp 代码以接受来自文具店的订单并显示并包括用户可以选择和订购的物品列表

[英]How to write a jsp code to accept order from stationary shop and display and to include list of items user can choose and order

Am a beginner in jsp and I've tried code in java.我是 jsp 的初学者,我已经尝试过 java 中的代码。 Here's my code in java这是我在 java 中的代码

import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
class ListDemo extends JFrame implements ListSelectionListener {
    Container cp;
    JList jlist;
    JLabel lblPrice;
    String[] prod = {
        “Pen”,
        ”Pencil”,
        ”Ruler”,
        ”Eraser”,
        ”Shapner”
    };
    int[] price = {
        12,
        13,
        15,
        45,
        25
    };
    ListDemo() {
        cp = this.getContentPane();
        cp.setLayout(new FlowLayout());
        jlist = new JList(items);
        lblPrice = new JLabel(“”);
        jlist.addListSelectionListener(this);
        cp.add(jlist);
        cp.add(lblPrice);
    }
    public void valueChanged(ListSelectionEvent e) {
        if (jlist.getSelectedIndex() == -1) {
            lblPrice.setText(“no items selected”);
        } else {
            int index = jlist.getSelectedIndex();
            lblPrice.setText(“Price: “+price[index]);
        }
    }
    public static void main(String args[]) {
        ListDemo lstObj = new ListDemo();
        lstObj.setSize(400, 400);
        lstObj.setVisible(true);
        lstObj.setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
}

In the above code ListSelectionListener is used to react to the change in selection of the value in JList Component.在上面的代码中,ListSelectionListener 用于对 JList 组件中值的选择变化做出反应。

Help me with JSP code帮助我使用 JSP 代码

You can below way.你可以在下面的方式。

 <html>
<head>
<script>
    function callFn(value) {
        alert(value)
    }
</script>
</head>
<body>
    <select onchange="callFn(this.value)">
        <option>1</option>
        <option>2</option>
        <option>3</option>
    </select>
</body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在JSP中订购包含商品的页面 - How to order a page with items in JSP 无法以正确的顺序显示来自SQL的数据,HTML JSP - Can't display the data from SQL in the correct order, HTML JSP 如何以自定义顺序在JSP文件中显示EnumSet? - How to display EnumSet in JSP file in custom order? 如何按大多数用户的位置顺序显示我的列表 (RecyclerView)? - How can I display my list (RecyclerView) in order of the most user's location? 使用 Java AWT 组件编写一个程序,以选择的顺序在列表中显示所选项目 - Write a program to display the selected items in a list in the order of selection using Java AWT Components 有关制作Java程序的建议,该程序将使用户能够从给定列表中选择一本书,输入数量并确认订单 - Advice on making a java program that will enable a user to choose a book from a given list, input quantity, and confirm the order 如何从线程将项目添加到列表并保持添加顺序? - How can I add items to a list from a thread and keep the adding order? 如何简化此代码以按降序对用户输入进行排序 - How can I simplify this code for sorting user input in descending order 列表关系中的项目顺序 - Order of items in List relationship 如何按特定的订单长度顺序列出字符串项目? - How do I list string items in a specific order length order?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM