Skip to content

Commit

Permalink
hzuapps#6 提交实验代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Danivy committed Nov 7, 2016
1 parent 25579b9 commit 62b6238
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/1414080902205")
public class Se1414080902205Servlet extends HttpServlet {

Expand Down Expand Up @@ -53,21 +54,30 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter();
String Account = new String(request.getParameter("account"));
String Amount = new String(request.getParameter("amount"));
String Account = "";
String Amount ="";
if(request.getParameter("username")!=null){
// System.out.println("fkldasjflkasjdkflas");
Account+=new String(request.getParameter("username"));
}

if(request.getParameter("passwd")!=null)
Amount= new String(request.getParameter("passwd"));
// out.print(Account);
// out.print(Amount);
HttpSession session=request.getSession(true);
String msg = "";
if (Account.equals("")) {
out.println("账号不能为空");
msg = "账号不能为空";
} else if (Amount.equals("")) {
out.println("转账金额不能为空");
msg = "转账金额不能为空";
} else {
boolean flat = true;
char[] str=Account.toCharArray();
for (int i = 0;i < Account.length();i++) {
int x = str[i] - '0';
if (!(x >= 0 && x <= 9)) {
out.println("请输入正确的账号");
msg = "请输入正确的账号";
flat = false;
break;
}
Expand All @@ -77,14 +87,22 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
for (int i = 0;i < Amount.length();i++) {
int x = sstr[i] - '0';
if (!(x >= 0 && x <= 9)) {
out.println("请输入正确的转账金额");
msg = "请输入正确的转账金额";
flat = false;
break;
}
}
}
if (flat) out.println("转账成功");
if (flat) msg = "转账成功";
}
System.out.println(msg);
request.setAttribute("message", msg);
request.getRequestDispatcher("/index.jsp").forward(request, response);
// System.out.println("dflajskldfjads");
session.setAttribute("message", msg);
// System.out.println(session.getAttribute("message").toString());
//System.out.println("fsfsdfsd");
// request.getSession().setAttribute("message",msg);
// String Account = "1414080902205";
// String Amount = "1414080902205";
// out.println(Account);
Expand Down
17 changes: 11 additions & 6 deletions jweb/web/1414080902205/index.jsp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
Expand All @@ -13,23 +14,26 @@ ATM Transfer
<center>Now time is:
<%=new java.util.Date()%>
</center>
<form id="register" action="servlet/Se1414080902205Servlet" method="post">
<form id="register" action="/LabForTwo/servlet/Se1414080902205Servlet" method="post">
<div class="form-group">
<label for="username1">Account *</label>
<input type="text" id="Account" class="form-control" />
<input type="text" name="username" class="form-control" />
</div>
<div class="form-group">
<label for="password1">Amount *</label>
<input type="password" id="Amount" class="form-control"/>
<input type="password" name="passwd" class="form-control"/>
<c:if test="${!empty sessionScope.message}">
<c:out value="${sessionScope.message}"></c:out>&nbsp;&nbsp;
</c:if>
</div>
<div style = "text-align:right;">
<button type="button" class="btn btn-default">Confirm</button>
<button type="submit" class="btn btn-default">Confirm</button>
</div>
</form>
</div>

</body>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<!-- <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
$( ".btn" ).click(function() {
Expand All @@ -42,9 +46,10 @@ ATM Transfer
type : "post",
datatype:"html",
success: function(data){
alert(data);
//alert(data);
}});
});
</script>
-->

</html>

0 comments on commit 62b6238

Please sign in to comment.