Java
1 package com.wql; 2 3 import javax.servlet.ServletException; 4 import javax.servlet.annotation.WebServlet; 5 import javax.servlet.http.HttpServlet; 6 import javax.servlet.http.HttpServletRequest; 7 import javax.servlet.http.HttpServletResponse; 8 import java.io.IOException; 9 10 /** 11 * Created by Lenovo on 2016/2/24. 12 */ 13 @WebServlet("/mytest") 14 public class Controller extends HttpServlet{ 15 @Override 16 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 17 doPost(req, resp); 18 } 19 20 @Override 21 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 22 req.setCharacterEncoding("UTF-8"); 23 String name=req.getParameter("name"); 24 req.setAttribute("name",name); 25 System.out.println("-sss-"); 26 req.getRequestDispatcher("index.jsp").forward(req, resp); 27 } 28 }
JSP
<%-- Created by IntelliJ IDEA. User: Lenovo Date: 2016/2/24 Time: 17:55 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>index</title> </head> <body> <form action="mytest" method="post"> <input name="name"> return:${name} <input value="提交" type="submit"> </form> </body> </html>
Web.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_3_1.xsd" version="3.1"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
可启动项目进行测试了
IntelliJ IDEA 15 部署Tomcat及创建一个简单的Web工程
原文:http://www.cnblogs.com/wql025/p/5215193.html