import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html;charset=\"utf-8\"");
PrintWriter out = resp.getWriter();
//获取从登录界面传递过来的参数值
/*
* 在此添加获取username和password值的语句
*/
String action = req.getParameter("action");
//这里是新加的代码
String username = req.getParameter("username");
String password = req.getParameter("password");
String action = req.getParameter("action");
if (action != null) {
/*
* 在此添加判断登录的条件
*/
if ( username.equals("admin")&&password.equals("123456")) {
printContent(out);
}
}
//获取点击了左侧导航栏链接时传递过来的值
String list = req.getParameter("list");
if (list != null) {
/*
* 在此添加 点击了主页后执行的操作
*/
if (list.equals("homepage")) {
out.println("<html>");
out.println("<h1>梁华</h1>");
out.println("<img src='1.jpg'>");
out.println("</html>");
}
}
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}
private void printContent(PrintWriter out) {
out.println("<html>");
out.println("<frameset cols='120,*'>");
out.println("<frame noresize='noresize' src='content/navlist.html'>");
out.println("<frame src='content/frameContent/ziliao.html' name='mainframe'>");
out.println("</frameset>");
out.println("</html>");
}
}
weibo_安然_无恙_80_0
相关分类