当前位置: 代码迷 >> Java Web开发 >> servlet中按钮如何用
  详细解决方案

servlet中按钮如何用

热度:8367   发布时间:2013-02-25 21:13:41
servlet中按钮怎么用
这是我没弄按钮之前的代码,共有两个按钮,一个是查询,一个是清空,现在只实现了查询功能,想加入按钮,不知道怎么见?请求大家的帮助!!!

package portalest;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MessageLog extends HttpServlet {

private static final long serialVersionUID = -4431868772435676256L;
public MessageLog() {
super();
}


public void destroy() {
super.destroy(); 
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Connection ct =null;
  Statement sm = null;
ResultSet rs = null;
String sql = null;
try{
  //解决中文乱码问题
response.setContentType("text/html;charset=gbk");
PrintWriter pw = response.getWriter();
String u = request.getParameter("uname");
  String p = request.getParameter("mtype");
  String b = request.getParameter("system1");
  String button1 = request.getParameter("button1");
 
 

Class.forName("oracle.jdbc.driver.OracleDriver");
ct = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "guodandan", "1");
sm = ct.createStatement();
if(u==null&&p==null&&b==null) {
sql = "select * from message_log";
 
}
else {
u = new String(u.getBytes("ISO-8859-1"),"GBK");
p = new String(p.getBytes("ISO-8859-1"),"GBK");
b = new String(b.getBytes("ISO-8859-1"),"GBK");

sql = "select * from message_log where uname='" + u +"' and mtype='"+p+"' and system1='"+b+"'";
System.out.println(sql);
}
rs = sm.executeQuery(sql);
 
pw.println("<HTML>");
pw.println(" <BODY>");
pw.print("<h1>消息日志监控管理</h1>");
pw.print("<h1>---------------------------------------------------------------------</h1>");
pw.print("<form action ='MessageLog' method = post name=f1>");
pw.print("用户:<input type = text name ='uname'>");
pw.print("消息类型:<select name = 'mtype' >");
pw.print("<option value='null' >---请选择---</option>"); 
pw.print("<option value='业务待办' >业务待办</option>"); 
pw.print("<option value='业务提醒' >业务提醒</option>"); 
pw.print("<option value='通知公告' >通知公告</option>"); 
pw.print("</select>"); 
pw.print("业务系统:<select name = 'system1'>");
pw.print("<option value='null' >---请选择---</option>"); 
pw.print("<option value='股权系统' >股权系统</option>"); 
pw.print("<option value='项目系统' >项目系统</option>"); 
pw.print("<option value='统计系统' >统计系统</option>"); 
pw.print("</select>"); 
pw.println("<input type = submit name='button1' value = 查询 onclick=send()>");
pw.println("<input type = submit name='button1' value = 清除日志 ><br>");
pw.println("<table border =1>");
pw.println("<tr>");
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!