JSP Jave如何将参数从jsp传递给java类 [英] JSP Jave how to pass parameter from jsp to java class
本文介绍了JSP Jave如何将参数从jsp传递给java类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好。
我有jsp页面,我想把这个jsp页面的参数传递给java类中的sql语句
和在另一个jsp页面中显示语句的输出。
谢谢
Hello everybody
I have jsp page and i want to pass parameter from this jsp page to sql statement in java class
and display output of statement in anther jsp page.
Thanks
推荐答案
有很多方法可以做到这一点。但最好的方法是使用MVC / MVC2(Model-View_Controller)模式。 Web中有很多教程,在开始之前阅读它们。
There are many way to do that. But the best approach is using MVC/MVC2(Model-View_Controller) pattern. Lots of tutorial are present in web, read them before start.
使用servlet很好......
下面给出的例子..
use servlet its fine...
example given below..
import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class Home1 extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name;
String date;
String time;
String guest;
String address;
String discription;
name=request.getParameter("name");
date=request.getParameter("date");
time=request.getParameter("time");
guest=request.getParameter("guest");
address=request.getParameter("address");
discription=request.getParameter("discription");
HttpSession session=request.getSession(true);
System.out.println("all is ok");
try {
sys.out.print(name);
sys.out.print(date);
sys.out.print(time);
sys.out.print(guest);
sys.out.print(address);
sys.out.print(discription);
} catch (Exception e) {
e.printStackTrace();
}
}
}
您可以在jsp页面中设置属性。转发到动作类时,可以使用getParameter方法在动作类中访问数据
You can set the attributes in jsp page. when forwarding to the action class, the data will be accessible in action class using getParameter method
这篇关于JSP Jave如何将参数从jsp传递给java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文