分享我的点点滴滴,在成长路上与你同行!

知识是在不断的学习,不断的积累,不断的创新,不断的........

IntelliJ IDEA 搭建JSP+Servlet的web开发多个(八)
创建一个项目
File -> New Project -> 输入项目名称“myjsps” ,选择Project SDK为1.8

二、创建一个Module
鼠标点中项目名称demos -> 右键选择New,选择Module 

单击Module如图所示:


ModuleName  lesson3


创建src|New|servlet


ServletName: TestServlet


创建完后,发现是红色的,说明没有导入Apache的包


按ctrl+shift+Alt+S 打开Project Structure |选中Source|创建文件夹classes,lib


在选择Dependencies依赖包


单击JARs or directories


 单击完成后!就不会出现红色的哦!


启动部署:

:

创建了三个web(lesson1,lesson2,lesson3)


运行页面

lesson3工程运行效果



Servlet

import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Administrator on 18-5-15.
 */
@javax.servlet.annotation.WebServlet(name = "TestServlet",urlPatterns = {"/tt"})
public class TestServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {

    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        response.setContentType("text/html;charaset=utf-8");
        PrintWriter out = response.getWriter();
        out.println("this is Servlet Annotation!");
    }
}

<a href="/tt">Click ME TT</a>


lesson1工程运行效果

 

@WebServlet(name = "LoginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         PrintWriter out=response.getWriter(); //写入对象
         response.setContentType("text/html;charset=utf-8");  //设置响应的字符集格式为UTF-8
         request.setCharacterEncoding("utf-8");
         String name=request.getParameter("uname");
         String pass=request.getParameter("upass");

         out.println(name+"\t"+pass);

          response.sendRedirect("my");

    }

 

@WebServlet(name = "MyServlet")
public class MyServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       //必须写这个内容类项
        response.setContentType("text/html;charset=utf-8");

        //输出对象
        PrintWriter out=response.getWriter();
        out.println("<html><head><body><a href='reg'>click Me@@</a></body></head></html>");

       // response.sendRedirect("reg");

        //最后要记得清空缓存区,并且关闭。
        out.flush();
        out.close();
    }
}


@WebServlet(name = "RegServlet",urlPatterns = {"/reg"})
public class RegServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        out.println("Test RegServlet Annotation!");
    }
}


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hlx20080808/article/details/80323083
个人分类: intellij IDEA
想对作者说点什么? 我来说一句

IntelliJ IDEA 12.0 Web开发及热部署

2012年12月23日 775KB 下载

Intellin IDEA搭建SSM框架

2018年02月11日 28.11MB 下载

没有更多推荐了,返回首页

不良信息举报

IntelliJ IDEA 搭建JSP+Servlet的web开发多个(八)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭