我想从jsp页面向servlet传递两个值。 1-结果集值,2-获取参数值。
它应该在jsp页面中看起来像这样:
SCcalculator.getValue(rs.getString("value1"),request.getParameter("value1"));
在servlet端如何在SCcalculator
包中接收和操作这些数据?有什么建议吗?
答案 0 :(得分:1)
在servlet类中使用:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
String s = request.getParameter("value1");
String s1 = request.getParameter("value");
}
在JSP中不要这样做,而是:
<form action="name" method="post"> //here action=name is name of your servlet class name
<input type="text" name="value">
<input type="text" name="value1">
<input type="submit" value="Send">
</form>
答案 1 :(得分:1)
考虑这个例子
<html>
<head>
<title>Demo application</title></head>
<body>
<form id = "form1" method = "GET" action = "../Sample Application">
link1 : <input type = "text" id = "nRequests" name = "nRequests" />
<input type = "submit" name = "submit" id = "submit"/>
</form></body></html>
现在servlet将如何接受请求
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
nRequests = request.getParameter("nRequests");
通过这种方式,您可以将HTML页面中的值传递给servlet。