JSP (Tomcat) POST, GET Parametern auslesen
tomcat.jpg
als JSP Datei speichern

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import = "java.util.*" %>
<html>
<head>
<title>JSP POST Parameter</title>
<meta name="author" content="hb">
</head>
<body>
<%
int counts = 0;
String hosts = "";
String ports = "";
Enumeration parameterList = request.getParameterNames();
while( parameterList.hasMoreElements() )
{
 String pName = parameterList.nextElement().toString();
 String[] pMultiple = request.getParameterValues( pName );
  if( 1 >= pMultiple.length ){
   if(request.getParameter( pName ) != ""){
    out.println("<div style='text-align:center;'><font size='+2' color='green'>" + pName + " = " + request.getParameter( pName ) + "</font></div>");
    counts++;
   }
  }else{
   for( int i=0; i<pMultiple.length; i++ ){
    if(pMultiple[i] != ""){
      out.println("<div style='text-align:center;'><font size='+2' color='green'>" + pName + "[" + i + "] = " + pMultiple[i] + "</font></div>");
      counts++;
     }
   }
  }
}
if(counts == 0){out.println("<div style='text-align:center;'><font size='+2' color='red'>Test POST Parameter</font></div>");}
if(request.getParameter("hosts")!= null){hosts = request.getParameter("hosts");}
if(request.getParameter("ports")!= null){ports = request.getParameter("ports");}
%>
<form name="posts" method="POST" action="tomcatpost.jsp">
<table align="center" width="800" border="0" cellpadding="2" cellspacing="2" style="margin-top:50px;">
 <tr>
  <td colspan="2"></td>
 </tr>
 <tr>
  <td><div style="margin-top:50px;">Host:*</div></td>
  <%
   out.println( "<td><div style='text-align:center;margin-top:50px;'><input type='Text' name='hosts' value='" + hosts + "' style='width:260px;'/></div></td>" );
  %>
 </tr>
 <tr>
  <td><div style="margin-top:20px;">Port:*</div></td>
  <%
   out.println( "<td><div style='text-align:center;margin-top:20px;'><input type='Text' name='ports' value='" + ports + "' style='width:260px;'/></div></td>" );
  %>
 </tr>
 <tr>
  <td> </td>
  <td>
   <div style="text-align:center;margin-top:20px;">
    <input type="submit" value="Submit">
   </div>
  </td>
 </tr>
</table>
</form>
</body>
</html>

       

Kopieren