XML文档配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>sec</servlet-name>
<servlet-class>myjavaweb.second</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sec</servlet-name>
<url-pattern>/myhomehtml</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>page</servlet-name>
<servlet-class>myjavaweb.pageservlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>page</servlet-name>
<url-pattern>/mypage</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>load</servlet-name>
<servlet-class>myjavaweb.zhuce</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>load</servlet-name>
<url-pattern>/loading</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>three</servlet-name>
<servlet-class>myjavaweb.three</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>three</servlet-name>
<url-pattern>/zc</url-pattern>
</servlet-mapping>
</web-app>
html基本规则填写即可,注意记住每个servlet类的别名和url 在跳转网页时需要用到
两个servlet用来输出html,提供按钮和记录跳转方向
package myjavaweb;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class pageservlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html;charset=utf-8");
resp.getWriter().write("<html>");
resp.getWriter().write("<head>");
resp.getWriter().write("欢迎登陆<br/>");
resp.getWriter().write("</head>");
resp.getWriter().write("<body>");
resp.getWriter().write("<form action='myhomehtml' method='post'>");
resp.getWriter().write("用户名:<input type='text' name='uname' value=''/><br/>");
resp.getWriter().write("密码:<input type='password' name='pwd' value=''/><br/>");
resp.getWriter().write("<input type='submit' value='登陆'/><br/>");
resp.getWriter().write("</form>");
resp.getWriter().write("<form action='loading' method='get'>");
resp.getWriter().write("<input type='submit' value='注册'/><br/>");
resp.getWriter().write("</form>");
re