<%@ page language="java" contentType="text/html charset=gbk"
pageEncoding="gbk"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
int id = Integer.parseInt(request.getParameter("id"))
int rootid = Integer.parseInt(request.getParameter("rootid"))
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=gbk">
<title>Replay</title>
</head>
<body>
<form method="post" action="ReplayOK.jsp">
<input type="hidden" name="id" value="<%=id %>">
<input type="hidden" name="rootid" value="<%=rootid %>">
<table align="center">
<tr>
<td>
<input type="text" name="title" size="80">
</td>
</tr>
<tr>
<td>
<textarea cols="80" rows="20" name="cont"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
</body>
</html>
---------------------------------------------------------------
下面接收上面表单中传过来的信息,并插入到mysql中
<%@ page language="java" contentType="text/html charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
request.setCharacterEncoding("GBK")
int id = Integer.parseInt(request.getParameter("id"))
int rootid = Integer.parseInt(request.getParameter("rootid"))
String title = request.getParameter("title")
String cont = request.getParameter("cont").replaceAll("\n","<br/>")
Connection conn = null
Statement st = null
Class.forName("com.mysql.jdbc.Driver")
conn = DriverManager.getConnection("jdbc:mysql://localhost/bbs?user=root&password=690115399")
st = conn.createStatement()
conn.setAutoCommit(false)
String sql = "insert into article values(null,?,?,?,?,now(),0)"
PreparedStatement pstmt = conn.prepareStatement(sql)
pstmt.setInt(1,id)
pstmt.setInt(2,rootid)
pstmt.setString(3,title)
pstmt.setString(4,cont)
pstmt.executeUpdate()
st.executeUpdate("update article set isleaf = 1 where id = " + id)
conn.commit()
conn.setAutoCommit(true)
st.close()
pstmt.close()
conn.close()
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=gbk">
<title>Insert title here</title>
</head>
<body>
<%response.sendRedirect("ShowArticleTree.jsp") %>
</body>
</html>
当然最好的方法还是应该用jsp + JavaBean方式。
先写一个实体类,就叫做User吧,然后再写hibernate的hbm配置文件,写UserDAO接口,然后在写UserDAOHibernateImpl实现UserDAO,在写spring配置文件定义好Hibernate的各种属性,然后再写一个UserService接口,然后就是根据spring的IOC写UserServiceImpl,然后就是写struts,struts的action可以这样写:public class RegisterAction{
private User user
public User getUser(){
return user
}
public void SetUser(User user){
this.user=user
}
public String execute(){
String[] confs =
{"applicationContext.xml"}
ApplicationContext ac =
new ClassPathXmlApplicationContext(confs)
UserService userService = (UserService)
ac.getBean("userService")
try{
userService.register(user)
return "success"
}catch(Exception e){
return "error"
}
}
}
(1)提交后,保存到一个静态集合或者Map中,保存好之后,然后就可以直接返回了。 但是这样会有一个问题,当你的服务器重新启动时,所有的数据将丢失。 (2)注册信息提交后,可以通过Java的序列化将数据保存在服务器的指定文件里,不提交到数据库。然后返回 (3)jsp提交信息后,调用邮件发送的接口,发送到指定的邮箱,然后立即返回。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)