Webapp 项目中在java包下新建一个服务端类
使用JOptionPane
框架组件 调用showMessageDialog
的方法实现
四个参数null,"这是一个信息对话框","信息",JOptionPane.INFORMATION_MESSAGE
还有确认对话框的代码showConfirmDialog
package servlet;
import javafx.scene.control.Alert;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.*;
import java.io.IOException;
@WebServlet(name = "DemoServlet",value = "/DemoServlet")
public class DemoServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("项目成功加载完胜");
//Alert alert = new Alert(Alert.AlertType.ERROR);
//System.out.println(alert);
System.out.println("对话框显示完毕");
JOptionPane.showMessageDialog(null,"这是一个信息对话框","信息",JOptionPane.INFORMATION_MESSAGE);
int result = JOptionPane.showConfirmDialog(null, "是否继续", "确认", JOptionPane.YES_OPTION);
if (result==JOptionPane.YES_OPTION) {
System.out.println("用户输入了是");
}else{
}
//显示一个输入对话框
String intput = JOptionPane.showInputDialog("请输入您的姓名:");
System.out.println("请输入您的姓名"+intput);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("完成了!!!!");
}
}
具体实现效果
总结
穷不失义,达不离道。——孔丘《论语》