Skip to content

Commit

Permalink
hzuapps#6 提交实验5
Browse files Browse the repository at this point in the history
  • Loading branch information
pigosy committed Nov 6, 2016
1 parent 93e8ec2 commit 81b07d0
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 23 deletions.
28 changes: 28 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902231/Goods.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package edu.hzu.javaweb.labs.se1414080902231;

public class Goods {

private String gN,dT,img;
Goods(String gN,String dT,String img)
{
this.gN=gN;
this.dT=dT;
this.img=img;
}

public String getgN()
{
return gN;
}

public String getdT()
{
return dT;
}

public String getimg()
{
return img;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,81 @@

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@SuppressWarnings("serial")
@WebServlet("/1414080902231")

public class Se1414080902231Servlet extends HttpServlet {

public Se1414080902231Servlet() {
super();
}

public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
super.destroy();
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("1414080902231");

String search=request.getParameter("search");

ArrayList<Goods> listz=new ArrayList<Goods>();
listz.add(new Goods("СÃ×","3999","a"));
listz.add(new Goods("÷È×å","2499","b"));
listz.add(new Goods("iphone","4888","c"));

List<Goods> list=new ArrayList<Goods>();
for(int i=0;i<listz.size();i++)
{
Goods c=listz.get(i);
if(search.equals(c.getgN()))
list.add(c);
}


if(list.size()!=0)
{
System.out.println("not null");
HttpSession session=request.getSession(true);
session.setAttribute("list", list);
}
else if(list.size()==0)
{
System.out.println("no");
HttpSession session=request.getSession(true);
session.setAttribute("list", null);
}

// else
// {
// response.setContentType("text/html");
// PrintWriter out = response.getWriter();
// out.println(0);
// }

response.setContentType("text/html");
PrintWriter out = response.getWriter();;
out.println("success!");
// request.setAttribute("list", list);
// request.getRequestDispatcher("index.jsp").forward(request, response);

}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("success!");
doGet(request,response);
}

public void init() throws ServletException {
// Put your code here
}

}
}
111 changes: 99 additions & 12 deletions jweb/web/1414080902231/index.jsp
Original file line number Diff line number Diff line change
@@ -1,21 +1,108 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ page import="edu.hzu.javaweb.labs.se1414080902231.Goods,java.util.ArrayList,java.util.List" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>勿闲闲物 Unused</title>
</head>
<body>
<button onclick="gotofabu()">发布二手货物</button><br/>
<br/>
<button onclick="">搜索二手货物</button>
<p></p>
<div align="right">
<input type="button" onclick="gotoLogin()" value="登陆" />&nbsp;
<input type="button" value="注册" />
</div>
<div align="center">
<p>
<font size="6">Welcome to Unused!</font>
</p>
</div>
<div align="center">
<form id="searchform">
<input type="text" name="search"/>
<input type="submit" value="搜索二手货物" />
<input type="button" onclick="gotofabu()" value="发布二手货物" />
</form>

</div>
<br/>
<div id="infomation" align="center">

<c:if test="${!empty sessionScope.list}">
<c:forEach var="l" items="${sessionScope.list}">
<c:out value="${l.gN}"/>&nbsp;&nbsp;
<c:out value="${l.dT}"/>&nbsp;&nbsp;
<c:out value="${l.img}"/>
<br/>
</c:forEach>

</c:if>


</div>

<%-- <%
List<Goods> list=(ArrayList<Goods>)session.getAttribute("list");
/* for (int i = 0; i < list.size(); i++)
{
out.print(list.get(i).getgN());
} */
// out.print(list.get(1).getgN());
out.print(session.getAttribute("list"));
%> --%>

</body>
<script>
function gotofabu()
{
window.location.href="issue.jsp";
}
<script type="text/javascript">
$("#searchform").submit(function(){
$.ajax({
type:"post",
data:$("#searchform").serialize(),
datatype:"text",
url:"1414080902231",
success:function(data){
}
});
});
</script>

<script type="text/javascript" >
function gotofabu() {
//window.location.href = "issue.jsp";
alert(2);
$.a();
}
$.a=function(){
$.ajax({
type:"post",
datatype:"text",
url:"issue.jsp",
success:function(data){
alert(data);
},
error:function(){
alert("请先登录!");
}
});
};
function gotoLogin() {
window.location.href = "login.jsp";
}
</script>

</html>

0 comments on commit 81b07d0

Please sign in to comment.