1、Java实验实验一Index.jsp: 请输入用户名: 请输入密码: Check.java/servletpublic void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException response.setContentType(text/html;charset=gb2312); String username=new String(request.getParameter(username).getBytes(iso-8859-1),gb2
2、312); String password=request.getParameter(password); user User=new user(); PrintWriter out=response.getWriter(); if(username=|password=) out.println(The username and the password would not be Null!); else if (username.equals(User.user1)|username.equals(User.user2) if (password.equals(User.password1
3、)&username.equals(User.user1) |(password.equals(User.password2)&username.equals(User.user2) out.println(Welcome!); else out.println(You are not the VIP!); out.flush(); out.close(); 实验二(1) login.jsp: 用户名: 密码: Check.jsp: Final.jsp: 用户名为: (2) login.jsp: 昵称: Message.jsp: alert(请先登录);location.href=login.
4、jsp; 欢迎来到聊天室 编号留言标题留言者昵称留言时间 a href=web_message/showmessage.jsp?id= 发新留言 Showmessage: 留言内容 返回列表 标题 时间 作者 内容 Addmessage.jsp 添加留言 返回列表 留言标题: 留言内容: Message_bean.javapackage bean;import java.util.Date;public class Message public Message() public Message(int id,String title,String nickname,String c
5、ontent) this.id = id; this.title = title; this.nickname = nickname; this.content = content; this.time = new Date().toString(); /编号、留言标题、留言者昵称、留言时间 private int id; private String title,nickname,content,time; public String getContent() return content; public void setContent(String content) this.conten
6、t = content; public int getId() return id; public void setId(int id) this.id = id; public String getTitle() return title; public void setTitle(String title) this.title = title; public String getNickname() return nickname; public void setNickname(String nickname) this.nickname = nickname; public Stri
7、ng getTime() return time; public void setTime(String time) this.time = time; (3) Add.jsp: 商品编号: 商品名字: 商品单价: 生产厂商: InsertServlet.java:package One;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http
8、.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import javax.servlet.http.HttpServlet;public class InsertServlet extends HttpServlet /* * The doPost method of the servlet. * * This method is called when a form has its tag value method equals to
9、 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
10、) throws ServletException, IOException response.setContentType(text/html;charset=gb2312); HttpSession session = request.getSession(); String no=new String(request.getParameter(NO).getBytes(iso-8859-1),gb2312);/(iso-8859-1),gb2312); String price=new String(request.getParameter(Price).getBytes(iso-885
11、9-1),gb2312); String name=new String(request.getParameter(Name).getBytes(iso-8859-1),gb2312); String factory=new String(request.getParameter(Factory).getBytes(iso-8859-1),gb2312); session.setAttribute(NO,no); session.setAttribute(Price,price); session.setAttribute(Name,name); session.setAttribute(Fa
12、ctory,factory); response.sendRedirect(addfinish.jsp); Addfinish.jsp 商品编号: 商品名字: 商品单价: 生产厂商: 实验三(1)student.jsppackage bean;public class student private String stuNum; private String stuName; private String telephone; private String email; private String address; private String postCode; public String
13、 getStuNum() return stuNum; public void setStuNum(String stuNum) this.stuNum = stuNum; public String getStuName() return stuName; public void setStuName(String stuName) this.stuName = stuName; public String getTelephone() return telephone; public void setTelephone(String telephone) this.telephone =
14、telephone; public String getEmail() return email; public void setEmail(String email) this.email = email; public String getAddress() return address; public void setAddress(String address) this.address = address; public String getPostCode() return postCode; public void setPostCode(String postCode) thi
15、s.postCode = postCode; Insert.javapublic class Insert extends HttpServlet public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException response.setContentType(text/html;charset=utf-8); request.setCharacterEncoding(utf-8); student stu1 =new student
16、(); stu1.setStuNum(request.getParameter(stuNum); stu1.setStuName(request.getParameter(stuName); stu1.setTelephone(request.getParameter(telephone); stu1.setAddress(request.getParameter(address); stu1.setEmail(request.getParameter(email); stu1.setPostCode(request.getParameter(postCode); int num; try num=Integer.parseInt(stu1.getStuNum().trim(); catch(Exception e)num=0; System.out.print(未输入学号!); String sqlString =null;/Sql 语句 sqlString =insert
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2