例如:以下图片
要用servlet做
具体内容就是:先写一个表单,表单中有用户名,密码,登录,和注册,当点击注册时就会连接到另外一页面进行注册,当填完注册表中信息后,点击提交按钮,进行提交,并把注册的数据提交到数据库中去。然后返回登录页面进行登录其实具体就是不知道怎样把注册的数据怎样与数据库联系起来,也不知道在servlt类中怎样写。。请教大家,希望大家能帮个忙,也希望大家给出详细的代码...在此谢谢大家了
要用servlet做
具体内容就是:先写一个表单,表单中有用户名,密码,登录,和注册,当点击注册时就会连接到另外一页面进行注册,当填完注册表中信息后,点击提交按钮,进行提交,并把注册的数据提交到数据库中去。然后返回登录页面进行登录其实具体就是不知道怎样把注册的数据怎样与数据库联系起来,也不知道在servlt类中怎样写。。请教大家,希望大家能帮个忙,也希望大家给出详细的代码...在此谢谢大家了
解决方案 »
- 急求高手来看看
- 请教一个COOKIE问题
- 在本页面获得文本框输入并作相应处理
- 这样的页面怎么自动关闭不了啊
- 我要放一个按钮,一点击就超链接到另一个页面,而不是新弹出来一个页面,紧急求购代码!!!!
- 有谁研究过velocity?我想与他(她)讨论
- 自定义标签的问题--在线等。
- 我要把我的jsp网站发布到网络上,又固定的Ip和空间,怎么才能发布?谢谢!在线等待!急!急!
- 如何启动Tomcat??
- 救急!启动时装载servlet!一定给分
- 怎么把表单分页啊~
- 提问一个问题,(jsp)我把所有图片查询出来了,name id 日期,发在文本框里,点击修改,我调试了一下,form里面什么都没有。。谢谢各位大虾
只不错利用servlet是用到action中间跳转页面而已
然后在web.xml里面配置一下servlet就行了
至于增删查改数据库里表的数据库
和以前写的代码是一样的,没有区别
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {。。}进行了查找和插入。。他报非法异常了
我QQ是307195009 能不能QQ上聊留言好麻烦的。。
import java.io.PrintWriter;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import dao.LoginDao;public class LoginServlet extends HttpServlet { /**
*
*/
private static final long serialVersionUID = 1L; /**
* Constructor of the object.
*/
public LoginServlet() {
super();
} /**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doPost(request,response);
} /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
PrintWriter out = response.getWriter();
request.setCharacterEncoding("gbk");
response.setCharacterEncoding("gbk");
②///String name =request.getParameter("name");
String pwd =request.getParameter("pwd");
////////////以上的是获得登录的名字和密码
String age =request.getParameter("age");
String sex =request.getParameter("sex");
String degree =request.getParameter("degree");
String phone =request.getParameter("phone");
③////String ic =request.getParameter("ic");
/////////////////////从②到③是获得插入的值要把他传到数据库去,
LoginDao ld=new LoginDao();
/////判断登录的名字和密码
boolean bb=ld.login(name, pwd);
if(bb){
response.sendRedirect("/test_login/MyS.jsp");
}else{
response.sendRedirect("/test_login/defeater.jsp");
}
//////////判断插入的数据
boolean bl=ld.insert(name, pwd, age, sex, degree, phone, ic);
if(bl){
response.sendRedirect("/test_login/MyS.jsp");
}else{
response.sendRedirect("/test_login/defeater.jsp");
}
out.flush();
out.close();
} /**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}} 但我可以查找登录用户,可在数据库中用已注册用户进行登录,就是不能插入数据是不是②③处的代码有问题??