[英]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.