Eclipse + JSP(HTML)+ Tomcat 开发网页

Eclipse开发完直接考到Tomcat路径下即可运行

 

新建

 

输入名称

 

更改编译路径

 

生成XML

完成.

 

创建Servlet

 

package pkg1;

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

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class JSPServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;
      

 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  PrintWriter out = response.getWriter();
  out.println("Hello,"+request.getParameter("user1"));
 }


 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  doGet(request,response);
 }

}

 

创建JSP

 

JSP代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Hello JSP</title>
 </head>
 <body>
  <form action="htmlact1" method = "post">
   <table>
    <tr>
     <td>User Name:</td>
     <td><input type = "text" name = "user1"></td>
    </tr>
    <tr>
     <td><input type = "submit"></td>
    </tr>
   </table>
  </form>
 </body>
</html>

 

修改web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

  <servlet>
    <servlet-name>HelloH1</servlet-name>
    <servlet-class>pkg1.JSPServlet</servlet-class>
  </servlet>

 
 
  <servlet-mapping>
    <servlet-name>HelloH1</servlet-name>
    <url-pattern>/htmlact1</url-pattern>
  </servlet-mapping>

 
</web-app>

 

部署

直接拷贝下面文件夹到tomcat路径下

 

改名

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值