0

i am new to java and jsp.. I have done a java code, i would like to add this java code into jsp Initially shown a web page to getting input from user once the user enter the information, it will call a java function

please let me know how to do this.. please..

public void createXmlTree(String name){
        Writer output = null;
        String addtext = "";            
        File file = new File("compare.txt");
        output = new BufferedWriter(new FileWriter(file));
        output.write(name);
        output.close();
}
String name1;
name1 = request.getParameter("text1");   
String name=name1;

try
{
  if (!(name.equals(null))) {
   createXmlTree(name);
   out.println("Successfull");
  }
}
catch(Exception e)
{
    System.out.println(e);
}
1
  • I think you just need to search for a tutorial about "Java Servlets" which will show you the basics. You should then read about "Expression Language" for outputting parameter values to the JSP. Commented May 7, 2011 at 15:44

1 Answer 1

1

Learn servlets.

Let the HTML form in the JSP submit to a servlet.

<form action="servleturl" method="post">

In the doPost() method of the servlet class you've all freedom to write Java code the way you want. When the business job is finished, you could store the result in request scope and forward to a result JSP file.

request.setAttribute("result", result);
request.getRequestDispatcher("/WEB-INF/result.jsp").forward(request, response);

In the /WEB-INF/result.jsp you can access the result by EL.

<p>Result: ${result}</p>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.