将JavaBean当成普通的类来用就是了。
解决方案 »
- 什么是classpath路径及ClassPathXmlApplicationContext()用法?
- struts2 jsp:include出现bug,高手请进
- struts2 验证码报错 org.apache.catalina.core.StandardWrapperValve invoke - Java / Web
- javascript有效性验证
- jsp页面找不到request内的对象啊?
- 在jsp中如何创建一个access
- JSP开发的过来人帮忙看看我的学习计划,谢谢!
- spring整合hibernate出错
- 求文件上传类
- 一个jsp运行出错的问题,谁能帮忙看看,与session和application有关
- 如何在JSP中修改表单的value?
- 哪里有免费的WEBLOGIC下载?
<head>
<%@ page contentType="text/html; charset=GB2312" %>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>我一直在努力ing</title>
</head><body>
<form action="http://localhost:8080/examples/servlet/addservlet" method="get">
<center>
<p> </p>
<font size=23>
<p><center>Write Message</center></p>
</font>
<p> </p>
<table align=cenetr width="496" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="79" height="30" align=center valign="top">Name:</td>
<td align=center valign="top"><input type="text" name="Name" size=55 height=23></td>
</tr>
<tr>
<td height="31" align=center valign="top">Email:</td>
<td align=center valign="top"><input type="text" name="Email" size=55 height=23></td>
</tr>
<tr>
<td height="32" align=center valign="top">Topic</td>
<td align=center valign="top"><input type="text" name="Topic" size=55 height=23></td>
</tr>
<tr>
<td height="102"></td>
<td align=center valign="top"><textarea rows=6 name=Note cols=55></textarea></td>
</tr>
</table>
</center> <center>
<p> <center>
<input type="submit" value="提交" >
<input type="reset" value="重写"></center>
</p>
</center>
<p> </p>
</form>
<p>
<center>
<a href=msgboard.jsp>先回去看看,一会儿在说</a>
</center>
</p>
</body>
</html>
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.net.URLEncoder;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class addservlet extends HttpServlet {
String Error = "";
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
String getName=request.getParameter("Name");
String getEmail=request.getParameter("Email");
String getTopic=request.getParameter("Topic");
String getNote=request.getParameter("Note");
UpdateMsg up=new UpdateMsg();
up.get_Name=getName;
up.get_Email=getEmail;
up.get_Topic=getTopic;
up.get_Note=getNote;
up.add();
Error = URLEncoder.encode("提交成功!");
response.sendRedirect("/msgboard.jsp?err="+Error);}
}
import java.io.*;
import java.util.*;
import java.lang.*;
//import java.util.Hashtable;
/*import java.util.Date;
import java.text.SimpleDateFormat;*/
public class UpdateMsg
{ String str;
Hashtable errors;
String name,email,topic,note;
public String get_Name="";
public String get_Email="";
public String get_Topic="";
public String get_Note="";
public void add()
{ try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:wordboard");
//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance() ;
//String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=wordboard" ;
//Connection cn=DriverManager.getConnection(url,"sa","");
str="INSERT INTO message(name,email,topic,note) VALUES ('"+get_Name+"','"+get_Email+"','"+get_Topic+"','"+get_Note+"')";
Statement st=cn.createStatement();
st.executeUpdate(str);
st.close();
cn.close();
}
catch(Exception ex )
{
System.out.println(ex.getMessage());
}
}
}