具体实现代码:
前端代码:
后台代码:
loginservlet:
package denglu.normal;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/login")
public class loginservlet extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
req.setCharacterEncoding("UTF-8");
String name=req.getParameter("username");
String password=req.getParameter("userpad");
resp.setContentType("text/html;charset=UTF-8");
PrintWriter out=resp.getWriter();
System.out.println(name);
System.out.println(password);
if("洲洲".equals(name)&&"123456".equals(password))
{
out.print("欢迎:'"+ name +"'使用");
out.print("您有邮件");
}
}
}
chaxunservlet:
package denglu.normal;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/chaxun")
public class chaxunservlet extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
String name=req.getParameter("username");
resp.setContentType("text/html;charset=UTF-8");
PrintWriter out=resp.getWriter();
out.print("欢迎:'"+ name +"'使用");
out.print("第一封邮件");
out.print("第二封邮件");
out.print("第三封邮件");
}
}
contenservlet:
package denglu.normal;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/content")
public class contentservlet extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
String name=req.getParameter("username");
resp.setContentType("text/html;charset=UTF-8");
PrintWriter out=resp.getWriter();
out.print("欢迎:'"+ name +"'使用");
out.print("所谓的焦虑就是书读得太少,而想得又太多了");
}
}