使用 jsp 简单表单和 java 代码
我是java和jsp新手.. 我已经做了一个java代码,我想将这个java代码添加到jsp中 最初显示一个网页以获取用户的输入 一旦用户输入信息,它将调用一个java函数
请让我知道如何做到这一点..拜托..
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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
了解 servlet。
让 JSP 中的 HTML 表单提交给 servlet。
在 servlet 类的
doPost()
方法中,您可以自由地按照自己想要的方式编写 Java 代码。当业务作业完成时,您可以将结果存储在请求范围中并转发到结果 JSP 文件。在
/WEB-INF/result.jsp
中,您可以通过 EL 访问结果。Learn servlets.
Let the HTML form in the JSP submit to a servlet.
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.In the
/WEB-INF/result.jsp
you can access the result by EL.