• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

How to get the information in a form

i need to get the information from the next form and write it to a file:

<FORM>
<SELECT name="UType" >
     <OPTION value="Provider">Chamberlain Provider</OPTION>
     <OPTION value="Intern">Chamberlain User</OPTION>
</SELECT>
<input type=hidden value="1" name="1"/>
<input type=submit value=Submit>
</FORM>
0
mmartha
Asked:
mmartha
2 Solutions
 
ldbkuttyCommented:
hi mmartha,
do you mean you want to get the form information and write it into a text file !?
why do you have hidden field !?
can you be more specific ?
0
 
mmarthaAuthor Commented:
yes, I meant to get the form information and write it into a text file. Ignore the hidden field.
0
 
TimYatesCommented:
<%
    String uType = request.getParameter( "UType" ) ;
%>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
TimYatesCommented:
Then, to write it into a file:

<%
    String uType = request.getParameter( "UType" ) ;
    FileWriter fw = null ;
    try
    {
        fw = new FileWriter( "/stats.txt", true ) ;
        fw.write( uType ) ;
        fw.write( "\n" ) ;
    }
    catch( IOException ex )
    {
        ex.printStackTrace() ;
    }
    finally
    {
        try { if( fw != null ) fw.close() ; } catch( IOException ex ) {}
    }
%>
0
 
TimYatesCommented:
that will append lines to the file "stats.txt" in the root folder of your machine...
0
 
ldbkuttyCommented:
If the file does not already exist, it is automatically created.
    try {
        BufferedWriter out = new BufferedWriter(new FileWriter("outfilename"));
        out.write(request.getParameter( "UType" ));
        out.close();
    } catch (IOException e) {
    }

0
 
TimYatesCommented:
You will need to add:

<%@ page import="java.io.*" %>

to the top of the jsp too ;-)
0
 
ldbkuttyCommented:
seems i am late... ;)
0
 
TimYatesCommented:
>  If the file does not already exist, it is automatically created.

That too ;-)
0
 
MacroLandCommented:
seems everything is all set :)
0
 
TimYatesCommented:
mmartha, how's it going?
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now