zoukankan      html  css  js  c++  java
  • web02-welcomeyou

    新建web项目web02-welcomeyou,

    修改index.jsp为

      <body>
        This is my JSP page. <br>
        <form action="welcome" method="get">
            请输入用户名:<input type="text" name="user"><p>
            <input type="submit" value="提交">
        </form>
      </body>

    其中,action的“welcome”要对应web配置中的url配置“/welcome”;

    method对应servlet中的doGet()方法;

    type="text"表示文本框,他的name是“user”,与后台接受的请求request中接收的参数为“user”一致;

    submit是提交按钮,这个按钮的内容是“提交”

    ----

    新建一个servlet,名字为WelcomeYou.java

    修改为://servlet接收了前台的“user”,对他说了“welcomeyou”,返回给前台

    public void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws ServletException, IOException {
    
            String user=req.getParameter("user");//获取到前台的name:user文本框中的值;前台过来的叫请求req。
            String welcomeInfo="Welcome you,"+user;//字符串的拼接
            
            resp.setContentType("text/html");
            
            PrintWriter out=resp.getWriter();
            out.println(welcomeInfo);
            out.close();
            
        }

    ----

    配置web.xml为

      <servlet>
        <description>This is the description of my J2EE component</description>
        <display-name>This is the display name of my J2EE component</display-name>
        <servlet-name>welcome</servlet-name>
        <servlet-class>WelcomeYou</servlet-class>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>welcome</servlet-name>
        <url-pattern>/welcome</url-pattern>
      </servlet-mapping>

    ----

    打开浏览器访问:localhost:8080/web02-welcomeyou/index.jsp

    点击提交

  • 相关阅读:
    08-认识margin
    07-border(边框)
    06-padding(内边距)
    05-盒模型
    04-层叠性权重相同处理
    03-继承性和层叠性
    MySQL安装与基本管理
    数据库概述
    并发编程练习
    selectors模块
  • 原文地址:https://www.cnblogs.com/zhaixing/p/5680766.html
Copyright © 2011-2022 走看看