corejava

Ads

 
 

Share on Google+Share on Google+

ramesh
corejava
2 Answer(s)      8 years ago
Posted in : Java Beginners
Ads
View Answers

August 7, 2008 at 8:46 AM


hai friend,

By using FormBeans we can get the data from from html by servlet,because it follows Frontcontroler design pattern(That means,it traps the request from the html page and get the FormData).


August 7, 2008 at 10:32 AM


Here is the code:


import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

import javax.sql.*;

import java.sql.*;



public class TxtFile extends HttpServlet{



public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException,IOException{

response.setContentType("text/html");



String username = request.getParameter("username").toString();



File f=new File("c:/textfile1.txt");

FileOutputStream fop=new FileOutputStream(f);



if(f.exists()){

String str=username;

fop.write(str.getBytes());



fop.flush();

fop.close();

System.out.println("The data has been written");

}



else

System.out.println("This file is not exist");



}

}
---------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<TITLE> New Document </TITLE>

<META NAME="Generator" CONTENT="EditPlus">

<META NAME="Author" CONTENT="">

<META NAME="Keywords" CONTENT="">

<META NAME="Description" CONTENT="">

</HEAD>



<BODY>

<form name="frm" action="txtFile" method="post">

<input type="text" name="username">

<input type="submit">

</form>

</BODY>

</HTML>

--------------------------------------------

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee";

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";

version="2.5">



<display-name>Welcome to Tomcat</display-name>

<description>

Welcome to Tomcat

</description>

<servlet>

<servlet-name>txtfile</servlet-name>

<servlet-class>TxtFile</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>txtfile</servlet-name>

<url-pattern>/txtFile</url-pattern>

</servlet-mapping>



</web-app>

-----------------------------------------------
Read for more information.

http://www.roseindia.net/servlets/

Thanks

Amardeep

Ads









Related Tutorials/Questions & Answers:
CoreJava Project
CoreJava Project  Hi Sir, I need a simple project(using core Java, Swings, JDBC) on core Java... If you have please send to my account
Advertisements
corejava - Java Beginners
corejava pass by value semantics  Example of pass by value semantics in Core Java.  Hi friend,Java passes parameters to methods using pass by value semantics. That is, a copy of the value of each of the specified
Corejava Interview,Corejava questions,Corejava Interview Questions,Corejava
;    Q 1. When should I use the abstract class rather...;   Q 2. What is hashcode? When is hashCode() used ? Ans : ... use the equals method to make an exact match.    Q 3. How can I get
Corejava Interview,Corejava questions,Corejava Interview Questions,Corejava
;    Q 1. How can I get the full path of Explorer.exe... that system can be access from an applet loaded via the Internet.     Q 2....   Q 3. Is it possible to convert a string to an abstract path ? Ans
Corejava Interview,Corejava questions,Corejava Interview Questions,Corejava
;    Q 1 : How should I create an immutable class ? Ans...; Q 2 : Is println overloading or overriding ?  Ans : The println() method...;     Q 3 : What is dynamic method dispatch ?  Ans
JList
JList  pls tell me about the concept the JList in corejava? and tell me a suitable example
core java - Java Beginners
core java  how to create a login page using only corejava(not servlets,jsp,hibernate,springs,structs)and that created loginpage contains database(ms-access) the database contains data what ever u r enter and automatically date
HOW TO BECOME A GOOD PROGRAMMER
HOW TO BECOME A GOOD PROGRAMMER  I want to know how to become good programmer   Hi Friend, Please go through the following link: CoreJava Tutorials Here you will get lot of examples with illustration where you can
What is Locale - Java Beginners
://www.roseindia.net/tutorial/java/corejava/javatext
Eclipse - IDE Questions
Eclipse  Hi To All.. I am new to ECLIPSE IDE. Please suggest me any book which can give me complete idea of setting environment and development with basic to advance development of java like(corejava,servlet,jsp,struts,ejb
Java Locale
/corejava/javatext/parseAndFormatDateUsingLocale.html Thanks
autentication & authorisation - JSP-Servlet
/interviewquestions/corejava/null-marker-interfaces-in-java.shtml Thanks
Tutorials   
Java Spring Hibernate Struts Training What type of programming language is Java? How do beginners learn about Java? ClassNotFoundException HttpRequestInterceptor java.lang.noclassdeffounderror: org/apache/http/httprequest noclassdeffounderror: org/apache/http/client/methods/httpurirequest java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017

Ads

 
Advertisement null

Ads