java - Why the Condition if(contentType.indexOf("multipart/form-data")>=0) is failed? -



java - Why the Condition if(contentType.indexOf("multipart/form-data")>=0) is failed? -

question: why next servlet printing "other thing happened". structures of loginservlet , index.jsp following. using netbeans 8.1 , apachetomcat 8.0.9.0 , browser chrome.

structure of loginservlet

import java.io.*; import javax.servlet.servletexception; import javax.servlet.http.*; public class loginservlet extends httpservlet { protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { string contenttype=request.getcontenttype(); printwriter out=response.getwriter(); //why next status failed. if((contenttype!=null)&&(contenttype.indexof("multipart/form-data")>=0)){//<==see datainputstream in =new datainputstream(request.getinputstream()); int formdatalength=request.getcontentlength(); out.print("contenttype not null"); byte [] databytes=new byte[formdatalength]; } if(contenttype==null) out.print("contenttype null"); else out.print("other thing happended");//<== why printing }

structure of index.jsp

<%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>jsp page</title> </head> <body> <form action="${pagecontext.request.contextpath}/loginservlet" method="post"> name: <input type="text" name="name"> <br> password: <input type="password" name="password"> <br> <input type="submit" value="login"> </form> </body>

output of browser "other thing happened".

the content type "multipart/form-data" should used submitting forms contain files, non-ascii data, , binary data.

if want upload file, content-type multipart/form-data guess success case uploading file.

your form submits input "other thing happened"

<form action="url" method="post" enctype="multipart/form-data"> <!-- code --> </form>

java jsp servlets netbeans netbeans-8.1

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -