buybook.jsp
来自「2. 实现用户注册」· JSP 代码 · 共 110 行
JSP
110 行
buybook.jsp:<%@ page contentType="text/html;charset=GB2312" %><%@ page import="aa.BuyBook" %> <%@ page import="aa.Login" %><%@ page import="aa.OrderForm" %><jsp:useBean id="login" class="Login" scope="session" ></jsp:useBean><jsp:useBean id="book" class="BuyBook" scope="session" ></jsp:useBean><jsp:useBean id="orderform" class="OrderForm" scope="page" ></jsp:useBean><%! //处理字符串的方法: public String codeString(String s) { String str=s; try{byte b[]=str.getBytes("ISO-8859-1"); str=new String(b); return str; } catch(Exception e) { return str; } }%><HTML><BODY ><Font size=1><table align="center"border="0"width="740"height="18"bgcolor=greencell spacing="1"><tr><td width="100%"><a href="<%=response.encodeURL("http://localhost:8080/test/showBookList.jsp")%>">书目浏览</a>|<a href="<%=response.encodeURL("http://localhost:8080/test/userRegister.jsp")%>">用户注册</a>|<a href="<%=response.encodeURL("http://localhost:8080/test/userLogin.jsp")%>">用户登陆 </a>|<a href="<%=response.encodeURL("http://localhost:8080/test/buybook.jsp")%>">订购图书 </a>|<a href="<%=response.encodeURL("http://localhost:8080/test/modifyForm.jsp")%>">修改定单 </a>|<a href="<%=response.encodeURL("http://localhost:8080/test/showOrderForm.jsp")%>">查看定单 </a>|<a href="<%=response.encodeURL("http://localhost:8080/test/modifyPassword.jsp")%>">修改密码 </a>|<a href="<%=response.encodeURL("http://localhost:8080/test/modifyMessage.jsp")%>">修改个人信息 </a></td></tr></table><% //如果客户直接进入该页面将被转向登录页面。 if(session.isNew()) {response.sendRedirect("userLogin.jsp"); } //如果没有成功登录将被转向登录页面 String success=login.getSuccess(); if(success==null) {success=""; } if(!(success.equals("ok"))) {response.sendRedirect("userLogin.jsp"); }%><%String str=response.encodeURL("buybook.jsp");%><FORM action="<%=str%>" Method="post" > <P>输入要订购的书的序列号: <Input type=text name="id"> <Input type=submit name="g" value="提交"></Form><jsp:setProperty name= "book" property="id" param="id" /> 查询到如下记录:<BR><% StringBuffer b=book.getMessageBybook_id();%><%=b%><P>如果准备订购该书,请填写订单,点击"添加到订单"按钮<BR> <%if((book.getId())!=0) {%> <FORM action="<%=str%>" method=post> <BR>您的用户名<Input TYPE=text name=logname value="<%=login.getLogname()%>" >* <BR>您的密码<Input TYPE=pasword name=pasword>* <BR>订购数量<Input TYPE=text name=mount value=1>(单位:册) <Input type=submit name="k" value="提交订单"> </FORM> <%} %> <% if((book.getId())!=0) { String name=request.getParameter("logname");//获取在表单中提交的用户名。 if(name==null) {name=""; } name=codeString(name); String word=request.getParameter("pasword");//获取在表单中提交的密码。 if(word==null) {word=""; } word=codeString(word); String mount=request.getParameter("mount");//获取在表单中提交的密码。 mount=codeString(mount); //判断提交的名字和密码是否正确: //如果正确就初始化orderform的值,并添加数据到订单。 if((name.equals(login.getLogname()))&&(word.equals(login.getPasword()))) { %> <jsp:setProperty name= "orderform" property="logname" value="<%=login.getLogname()%>"/> <jsp:setProperty name= "orderform" property="realname" value="<%=login.getRealname()%>"/> <jsp:setProperty name= "orderform" property="order_number" value="<%=book.getOrder_number()%>"/> <jsp:setProperty name= "orderform" property="book_name" value="<%=book.getBook_name()%>"/> <jsp:setProperty name= "orderform" property="mount" value="<%=mount%>"/> <jsp:setProperty name= "orderform" property="phone" value="<%=login.getPhone()%>"/> <jsp:setProperty name= "orderform" property="address" value="<%=login.getAddress()%>"/> <% String ms=orderform.setOrderBook(); out.print("<BR>"+ms); } else { out.print("<BR>"+"您必须输入正确的密码和用户名"); } } %></Font></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?