package com.jingmt.middle;
import com.jingmt.database.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class ControlServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
private PreparedStatement pstmt;
private ResultSet rs;
private ArrayList alist;
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
int id=0;
String str_id=request.getParameter("uid");
alist=new ArrayList();
try
{
id=Integer.parseInt(str_id) ;
}
catch(NumberFormatException ex)
{
request.setAttribute("error",str_id);
request.getRequestDispatcher("/jsp/Error.jsp").forward(request,response);
return ;
}
if(!(0
request.setAttribute("error",str_id);
request.getRequestDispatcher("/jsp/OutOfBoundsError.jsp").forward(request,response);
return;
}
String sql="select ProductID,ProductName,UnitPrice from Products where ProductID ";
ConnDB db=new ConnDB();
Connection conn=db.getConn();
try
{
pstmt=conn.prepareStatement(sql);
pstmt.setInt(1,id+1);
rs=pstmt.executeQuery();
while(rs.next())
{
ArrayList list=new ArrayList();
for(int i=0;i<3;i++)
{
list.add(rs.getString(i+1));
}
alist.add(list);
}
}
catch(Exception ex)
{
System.out.println(ex.getMessage()+"controlservlet1");
}
// request.setAttribute("list",alist);
// request.getRequestDispatcher("/showservlet").forward(request,response);
HttpSession session=request.getSession();
session.setAttribute("list",alist);
response.sendRedirect("showservlet");
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}
ShowServlet£º
package com.jingmt.client;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class ShowServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
private ArrayList alist;
int noPage;
int n;
int currPage=0;
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
// alist=(ArrayList)request.getAttribute("list");
alist=(ArrayList)request.getSession().getAttribute("list");
if(n!=0)
try{
n=Integer.parseInt(request.getParameter("n"));
}
catch(NumberFormatException ex1)
{
System.out.print(ex1.getMessage()+"here1");
return;
}
else
{
n=0;
}
ArrayList result_alist;
result_alist=this.getItemsFromPage(alist,n);
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("");
out.println("
out.println("");
out.print("");
out.println(" ProductID ");
out.println(" ProductName ");
out.println(" UnitPrice ");
out.println("
");
if (result_alist == null) {
result_alist = new ArrayList();
}
for (int i = 0; i < result_alist.size(); i++) {
ArrayList l = (ArrayList) result_alist.get(i);
for (int j = 0; j < l.size(); j++) {
out.println(l.get(j) + " ");
}
out.println("
");
}
out.println("");
out.println("");
out.close();
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
public void destroy() {
}
public ArrayList[] divide(ArrayList arraylist) {
noPage = (arraylist.size()-1)/ 10 + 1;
ArrayList[] result = new ArrayList[noPage];
for (int i = 1; i < noPage; i++) {
result[i - 1] = new ArrayList();
for (int j = 0; j < 10; j++) {
result[i - 1].add(arraylist.get((i - 1) *10+ j));
}
}
for (int i = (noPage - 1) *10; i < arraylist.size(); i++) {
result[noPage - 1] = new ArrayList();
result[noPage - 1].add(arraylist.get(i));
}
return result;
}
public ArrayList getItemsFromPage(ArrayList arraylist, int pageNum) {
ArrayList[] result = this.divide(arraylist);
return result[pageNum];
}
你用堆栈就可以实现这个操作。
你可以参考一下如何实现计算表达式(也就是表达式计算器)
应该是个数据结构方面的问题吧? 不过你这个问题太可怕了,你到底想干什么? 还原成内存映像,你是想展示这个表达式在逻辑内存中的相对位置吗?
朋友你很专业,但是太专业的问题在百度上面很难找到答案,所以还是建议找老师或者专家请教。。。在这里很难遇到具体的回答的
有没有电脑专业的高手能帮帮我?下面1道题目如何用英文回答?那是1道operating system 的题目.
Discuss situations under which the most frequently used page – replacement algorithm generates fewer page faults than the least recently used page – replacement algorithm. Also discuss under what circumstance the opposite holds.
谁能用英文回答1下这道题?谢谢