1,Fragment :建一个web应用做成几个部分,然后整合(new一个fragment的项目写完,导出成.jar再将该包添加在web项目中的webcontent->WEB-INF下面的lib包下)
image.png
创建时可以不进行勾选web.xml应为fragment中也会存在一个fragment.xml可进行配置
image.png
创建完成后再创建
image.png
image.png
创建分项目完成后创建类并继承HttpServlet进行编写代码
例如
package com.ieek.ew;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.Executor;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
public class FragmentGG extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
processRequest(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
processRequest(req,resp);
}
private void processRequest(HttpServletRequest req, HttpServletResponse resp)throws IOException,ServletException {
req.setCharacterEncoding("UTF-8");
Map<String,String[]> may= req.getParameterMap();//获取所有的键值对
Set<Entry<String, String[]>> set = may.entrySet();//转换为set集合进行遍历
StringBuilder sb = new StringBuilder();//创建StringBuilder进行接受数据并打印
for(Entry<String, String[]> entry:set) {
sb.append("<h3>").append(entry.getKey()).append("->").append(Arrays.deepToString(entry.getValue())).append("</h3>");
System.out.println(entry.getValue());//打印:
System.out.println(entry.getValue().toString());
System.out.println(Arrays.deepToString(entry.getValue()));
}
resp.setCharacterEncoding("UTF-8");
resp.setContentType("text/html;charset=UTF-8");
resp.getWriter().write(sb.toString());
}
}
image.png
image.png
导出为jar包
image.png
导出后将该jar包复制粘贴至
image.png
image.png
网友评论