开发者

working with jsp simple form along with java code

开发者 https://www.devze.com 2023-03-03 09:03 出处:网络
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

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);
}


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消