Java/JSP/Form TextField

Материал из Java эксперт
Версия от 10:09, 1 июня 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Form TextField Demo

   <source lang="java">

//File: index.html <html>

 <body>

Hello Web Application

   <form action="hello.jsp" method="POST" >
What is your name?
           <input type="text" name="name" />

<input type="submit" name="Submit" value="Submit name" /> <input type="reset" name="Reset" value="Reset form" />

   </form>
 </body>

</html> //File: hello.jsp <html>

 <head>
   <title>Hello Web Application</title>
 </head>
 <body>

Hello Web Application

   

<% String name = request.getParameter("name"); if (name.trim().length() == 0) {  %> You did not tell me your name!


<% } else {  %> Hello <%=name%>


<% }  %>


Inserting Text into Text Fields

   <source lang="java">

//File: index.html <HTML>

 <HEAD>
   <TITLE>Inserting Text into Text Fields</TITLE>
 </HEAD>
   <BODY>

Inserting Text into Text Fields

       <FORM NAME="form1" ACTION="formAction.jsp" METHOD="POST">
           <INPUT TYPE="TEXT">
           <INPUT TYPE="SUBMIT" VALUE="Click Me!">
       </FORM>
   </BODY>

</HTML>

//File: formAction.jsp <HTML>

 <HEAD>
   <TITLE>Inserting Text into Text Fields</TITLE>
 </HEAD>
   <BODY>

Inserting Text into Text Fields

       <FORM NAME="form1">
           <INPUT TYPE="TEXT" VALUE="Hello from JSP!">
           <INPUT TYPE="SUBMIT" VALUE="Click Me!">
       </FORM>
   </BODY>

</HTML>

      </source>
   
  
 
  



Submitting Text Fields

   <source lang="java">

//File: index.html <HTML>

   <HEAD>
       <TITLE>Submitting Text Fields</TITLE>
   </HEAD>

   <BODY>

Submitting Text Fields

       <FORM ACTION="formAction.jsp" METHOD="POST">
           Please enter your name:
           <INPUT TYPE="TEXT" NAME="text1">
           
<INPUT TYPE="SUBMIT" value="Submit"> </FORM> </BODY>

<HTML>

///////////////////////////////////////////////////////////////////////// //File: formAction.jsp <HTML>

 <HEAD>
   <TITLE>Reading Data From Text Fields</TITLE>
 </HEAD>
   <BODY>

Reading Data From Text Fields

       Your name is 
       <% out.println(request.getParameter("text1")); %>
  </BODY>

</HTML>


      </source>
   
  
 
  



Submitting Text Fields 2

   <source lang="java">

//File: index.html <HTML>

   <HEAD>
       <TITLE>Submitting Text Fields</TITLE>
   </HEAD>

   <BODY>

Submitting Text Fields

       <FORM ACTION="formAction.jsp" METHOD="POST">
           Please enter your name:
           <INPUT TYPE="TEXT" NAME="text1">
           
<INPUT TYPE="SUBMIT" value="Submit"> </FORM> </BODY>

<HTML>

//File:formAction.jsp <HTML>

   <HEAD>
       <TITLE>Decoding an HTTP Request</TITLE>
   </HEAD>

   <BODY>

Request Information

       JSP request method: <%= request.getMethod() %>
       
URL for the request: <%= request.getRequestURI() %>
Protocol of the request: <%= request.getProtocol() %>
Server name: <%= request.getServerName() %>
Path: <%= request.getServletPath() %>
Server port: <%= request.getServerPort() %>
Remote address: <%= request.getRemoteAddr() %>
Remote host: <%= request.getRemoteHost() %>
Locale: <%= request.getLocale() %>
User agent: <%= request.getHeader("User-Agent") %> </BODY>

</HTML>


      </source>