# Frage zu Get- bzw. Postrequest in JSP.



## pkm (29. Okt 2019)

Ich habe mal eine einfache Seite in JSP gemacht:


```
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@ page import="java.io.*,java.util.*, javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>

<%@ page import="java.io.*,java.util.*, javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
 


<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<script type='text/javascript' src="jquery-3.4.1.js"></script>
<link rel="stylesheet" href="custom.css">
<link href="bootstrap-3.3.5/css/bootstrap.min.css" rel="stylesheet">
<script src="bootstrap-3.3.5/js/bootstrap.min.js"></script>
<title></title>
</head>
<body class="body">
 

    <form class="form-horizontal" method="get" enctype="text/html"
        action="main.jsp">

        <div class="container">
            <div class="row">
                <div class="control-group col-sm-3">
                    <label id="vorname_label" for="checkIn">Vorname:</label>
                    <div id="vorname_container">
                        <div class="input-group text">
                            <input type="text" id="vorname" name="vorname"
                                class="form-control" autofocus>
                        </div>
                    </div>
                </div>
                <div class="control-group col-sm-9">

                    <label id="nachname_label" for="checkIn">Nachname:</label>
                    <div id="nachname_container">
                        <div class="input-group text">
                            <input type="text" id="nachname" name="nachname"
                                class="form-control">
                        </div>
                    </div>

                </div>
            </div>
 
            <div class="col-sm-2">
                <button type="submit" class="btn btn-success" id="senden" style="margin:5px;" >Senden</button>
            </div>
        </div>

    </form>
 

   <p style="margin-left:100px; margin-top:10px;">CV hochladen (optional)</p>

   <div style="margin-left:100px; margin-top:10px;">

    <form id="cv" method="post" enctype="multipart/form-data"
        action="main.jsp">
        <input id="fileinput" type="file" name="fileinput" size="50" accept=".pdf" />
        <button type="submit" style="margin-top:10px;">Datei Senden</button>
    </form>

   </div>

    <%
    
        String file = request.getParameter("fileinput");
    
        System.out.println(file);
        
    %>



</body>
</html>
```

Wenn ich Vor- und Nachnamen ausfülle und dann den get-Request an dieselbe Seite sende (main.jsp), dann ist request.getParameter("fileinput") sinniger Weise null.

Wenn ich nun aber durch den Filechooser eine Datei auswähle und dann auf den Datei senden - Button klicke, dann ist request.getParameter("fileinput") immer noch null. Wieso ist das so bzw. was habe ich da übersehen?


----------



## Ullenboom (1. Nov 2019)

Siehe https://stackoverflow.com/questions...s-to-server-using-jsp-servlet/2424824#2424824:



> Before Servlet 3.0, the Servlet API didn't natively support multipart/form-data. It supports only the default form enctype of application/x-www-form-urlencoded. The request.getParameter() and consorts would all return null when using multipart form data. This is where the well known Apache Commons FileUpload came into the picture.


----------

