package com.zhan;
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 FileServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String username = req.getParameter("username");//接收参数
System.out.println(username);//验证是否接收成功
req.getRequestDispatcher("success.jsp").forward(req,resp);//转发页面
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
2.编写前端页面(JSP)
<%@page contentType="text/html; charset=UTF-8" language="java" %>
$Title$
注意action中填写的应该是第一步自定义的FileServlet,表示提交该页面的数据到此Servlet中
3.在web.xml中配置FileServlet
Archetype Created Web Application
FileServlet
com.zhan.FileServlet
FileServlet
/FileServlet
4.结果
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)