Tomcat JSP

栏目: JSP · 发布时间: 5年前

内容简介:Tomcat修改目录下的

Tomcat

修改端口号

修改目录

/opt/apache-tomcat-9.0.16/conf

下的

servle.xml
<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

修改即可

重启从新加载

虚拟目录

新建文件

/home/ming/demo

然后WEB-INF文件中增加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_4_0.xsd"
         version="4.0">
</web-app>

然后接着,继续修改servle.xml文件

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />
        <Context path="/" docBase="/home/ming/demo/"/>

接着在目录下新建jsp文件

<%
  out.println("hello world");
%>

此时,访问的时候,会生成 java 文件,再次编译成为class文件

在work文件里可以找到。日志在log文件里。

交互性

<form class="" action="index.jsp" method="post">
  <input type="text" name="info">
  <input type="submit" name="" value="show">
</form>
<%
  String str = request.getParameter("info");
  out.println(str);
%>

jsp

定义局部变量

<%--
  Created by IntelliJ IDEA.
  User: ming
  Date: 19-3-6
  Time: 下午9:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
    <%
      int x = 10;
      String info = "ming";
      out.println(x + info);
    %>
  </body>
</html>

全局变量

全局变量是<%!%>

表达式输出

<%--
  Created by IntelliJ IDEA.
  User: ming
  Date: 19-3-6
  Time: 下午9:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
    <%
      String info = "ming";
    %>
    <h3>info = <%=info%></h3>
  </body>
</html>

循环输出列表

<%--
  Created by IntelliJ IDEA.
  User: ming
  Date: 19-3-6
  Time: 下午9:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
    <table border=="1" width="100%">
      <%
        int rows = 10;
        int cols = 10;
        for(int x = 0; x < rows; x++){
      %>
        <tr>
          <%
            for(int y = 0; y < cols; y++){
          %>
              <td><%=(x * y)%></td>
          <%
            }
          %>
        </tr>
      <%
        }
      %>
    </table>
  </body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Google将带来什么?

Google将带来什么?

杰夫·贾维斯 / 陈庆新、赵艳峰、胡延平 / 中华工商联合出版社 / 2009-8 / 39.00元

《Google将带来什么?》是一本大胆探索、至关重要的书籍,追寻当今世界最紧迫问题的答案:Google将带来什么?在兼具预言、宣言、思想探险和生存手册性质的这样一《Google将带来什么?》里,互联网监督和博客先锋杰夫·贾维斯对Google这个历史上发展速度最快的公司进行了逆向工程研究,发现了40种直截了当、清晰易懂的管理与生存原则。与此同时,他还向我们阐明了互联网一代的新世界观:尽管它具有挑战性......一起来看看 《Google将带来什么?》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换