servlet本来就应该充当控制器的角色,下面是一个简单的例子
jsp:
-------------------------------------------------
<form method="post" action="servlet1">
<input type="text" name="uid">
<input type="submit">
</form>
bean:
-------------------------------------------------
public class Bean2{
public String getReq(String str) {
return str;
}
}
servlet:
-------------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class Servlet1 extends HttpServlet {
static final private String CONTENT_TYPE = "text/html;
charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Post request
public voiddo
Post(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String str = request.getParameter("uid");
Bean2 b = new Bean2();
out.println(b.getReq(str));
}
public void destroy() {
}
}