12-31 javaee jsp servlet的实现

webserver
    apache tomcat

    tomcat.apache.org       
    
tomcat 使用
-------------------------
1) 官方下载  apache-tomcat-9.0.30-windows-x64.zip

2) 解压 apache-tomcat-9.0.30-windows-x64.zip 到 c:/tomcat

3) c:/tomcat/bin/startup.bat 为服务器的启动文件,如果点击后窗口自动关闭。应该jdk环境变量没有配置好。

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;.;D:\jdk\jdk-13.0.1\bin;D:\jdk\jdk-13.0.1\lib;D:\scala-2.13.1\bin;D:\Python38;D:\Python38\Scripts;C:\nodejs\


%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;.;%JAVA_HOME%\bin;%JAVA_HOME%\lib;D:\scala-2.13.1\bin;D:\Python38;D:\Python38\Scripts;C:\nodejs\


4)建立环境变量
JAVA_HOME
CLASSPATH
CATALINA_HOME = c:\tomcat
PATH 

 

5)c:/tomat/conf/logging.properties  修改一下
#java.util.logging.ConsoleHandler.encoding = UTF-8
java.util.logging.ConsoleHandler.encoding = GBK


6)bin/startup.bat 启动服务器 默认端口8080

  http://localhost:8080


7)关闭服务器 /bin/shutdown.bat 


服务器端口号
-------------------------------
tomcat 8080
网络服务器 默认是80
http://baidu.com:80
http://baidu.com

http://localhost

如果要修端口号,打开 conf/server.xml 

原来是 
  <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

  <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

在tomcat上部署自己的war项目


java web项目结构

web
webapp
webapp

    /
     WEB-INF
        classes 项目中使用的类
        lib jar
        web.xml 项目的配置文件 版本 2.5  3.0 3.1 4.0

     META-INF 信息目录

     index.jsp
     index.html
     images/a.jpg

java maven web项目结构

/src/
    /main
       /java
    /resources
    /webapp
        /WEB-INF
            /lib
            /classes
            /web.xml 
        index.jsp
   /text
       /java
/pom.xml maven项目核心配置文件
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>webok</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <name>webok</name>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>13</maven.compiler.source>
        <maven.compiler.target>13</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.18</version>
        </dependency>
    </dependencies>


    <build>
        <finalName>${project.artifactId}</finalName>
        <testSourceDirectory>src/test/java</testSourceDirectory>
        <sourceDirectory>src/main/java</sourceDirectory>
        <!-- 处理无法加载资源配置文件 -->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-compiler-plugin</artifactId>
               <version>3.8.1</version>
               <configuration>
                   <source>13</source>
                   <target>13</target>
                   <encoding>UTF-8</encoding>
               </configuration>
            </plugin>
        </plugins>
    </build>
</project>

javaweb
    本质servlet开发
    
    servlet

    tomcat jsp jstl EL servlet
           
           servlet 模板引擎
                      freemarker apache 
              thyemleaf html5

web项目两大对象
HttpServletRequest 请求对象  get post
HttpServletResponse 响应对象


get
<a href="save.do?id=6">aaaa</a>

save.java servlet
reqeust.getParamter("id")


上传文件
   jspsmartupload
   apache commons-fileupload 
   cos 出版社 O'reilly系列
   java servlet 3 实现了上传功能


<%@ page contentType="text/html;charset=utf-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>webrx</title>
</head>
<body>
<h3>单文件上传</h3>
<form action="upload" method="post" enctype="multipart/form-data">
    照片: <input type="file" name="ufile"> <input type="submit" value="提交">
</form>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值