servlet 怎么获取页面的表单 传送到后台 5
jsp页面所提交的参数提交到servlet里面,问下在servlet里面(就是下面的?怎么写)怎么写我已经在dao里面写好方法elseif("insert".equals...
jsp 页面所提交的参数提交到 servlet 里面,问下在 servlet 里面(就是下面的 ? 怎么写)怎么写 我已经在 dao 里面写好方法
else if("insert".equals(param))
{
(
?
)
success = dao.insertXue(xue);
if(success)
{
out.print("<script>alert('添加成功');location.href='/HNReader/xue?param=selectXueList'</script>");
}
else
{
out.print("<script>alert('添加失败');</script>");
return;
}
} 展开
else if("insert".equals(param))
{
(
?
)
success = dao.insertXue(xue);
if(success)
{
out.print("<script>alert('添加成功');location.href='/HNReader/xue?param=selectXueList'</script>");
}
else
{
out.print("<script>alert('添加失败');</script>");
return;
}
} 展开
8个回答
2015-12-07 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
工程名:ServletStudy
表单文件:login.jsp
Servlet文件:LoginServlet.java
配置文件:web.xml
下面对是这几个文件的代码:
login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'login.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head
<body>
<form action="/ServletStudy/LoginServlet">
userName: <input name="userName" type="text"/><br/>
password: <input name="password" type="password"/><br/>
<input type="submit"value="submit"/> <input type="reset"value="reset"/>
</form>
</body>
</html>
LoginServlet.java
package com;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class LoginServlet extends HttpServlet
{
表单文件:login.jsp
Servlet文件:LoginServlet.java
配置文件:web.xml
下面对是这几个文件的代码:
login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'login.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head
<body>
<form action="/ServletStudy/LoginServlet">
userName: <input name="userName" type="text"/><br/>
password: <input name="password" type="password"/><br/>
<input type="submit"value="submit"/> <input type="reset"value="reset"/>
</form>
</body>
</html>
LoginServlet.java
package com;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class LoginServlet extends HttpServlet
{
展开全部
比如表单里是这样的:
<form>
<input type="text" name="test" />
</form>
在servlet可以这样取得表单里是数据:
String test= request.getParameter("test");
<form>
<input type="text" name="test" />
</form>
在servlet可以这样取得表单里是数据:
String test= request.getParameter("test");
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
request.getParameter("表单中的name属性");
//获取表单提交上来的参数
//获取表单提交上来的参数
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
request.getParameter("ParameterName");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
else if("insert".equals(param))
{
(
String xue = request.getParameter("xue");
)
success = dao.insertXue(xue);
if(success)
{
out.print("<script>alert('添加成功');location.href='/HNReader/xue?param=selectXueList'</script>");
}
else
{
out.print("<script>alert('添加失败');</script>");
return;
}
}
{
(
String xue = request.getParameter("xue");
)
success = dao.insertXue(xue);
if(success)
{
out.print("<script>alert('添加成功');location.href='/HNReader/xue?param=selectXueList'</script>");
}
else
{
out.print("<script>alert('添加失败');</script>");
return;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
servlet里面可以用..
request.getParameter("name")来获得表单对应名称为name的组件的值..
比如你有个名称叫name的输入框..用这个就可以获得那个输入框的value..就是输入的字符串..
request.getParameter("name")来获得表单对应名称为name的组件的值..
比如你有个名称叫name的输入框..用这个就可以获得那个输入框的value..就是输入的字符串..
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
工程名:ServletStudy
表单文件:login.jsp
Servlet文件:LoginServlet.java
配置文件:web.xml
下面对是这几个文件的代码:
login.jsp
<%@
page
language="java"
import="java.util.*"
pageEncoding="UTF-8"%>
<%
String
path
=
request.getContextPath();
String
basePath
=
request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE
HTML
PUBLIC
"-//W3C//DTD
HTML
4.01
Transitional//EN">
<html>
<head>
<base
href="<%=basePath%>">
<title>My
JSP
'login.jsp'
starting
page</title>
<meta
http-equiv="pragma"
content="no-cache">
<meta
http-equiv="cache-control"
content="no-cache">
<meta
http-equiv="expires"
content="0">
<meta
http-equiv="keywords"
content="keyword1,keyword2,keyword3">
<meta
http-equiv="description"
content="This
is
my
page">
<!--
<link
rel="stylesheet"
type="text/css"
href="styles.css">
-->
</head
<body>
<form
action="/ServletStudy/LoginServlet">
userName:
<input
name="userName"
type="text"/><br/>
password:
<input
name="password"
type="password"/><br/>
<input
type="submit"value="submit"/>
<input
type="reset"value="reset"/>
</form>
</body>
</html>
LoginServlet.java
package
com;
import
java.io.IOException;
import
java.io.PrintWriter;
import
javax.servlet.ServletException;
import
javax.servlet.http.HttpServlet;
import
javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public
class
LoginServlet
extends
HttpServlet
{
表单文件:login.jsp
Servlet文件:LoginServlet.java
配置文件:web.xml
下面对是这几个文件的代码:
login.jsp
<%@
page
language="java"
import="java.util.*"
pageEncoding="UTF-8"%>
<%
String
path
=
request.getContextPath();
String
basePath
=
request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE
HTML
PUBLIC
"-//W3C//DTD
HTML
4.01
Transitional//EN">
<html>
<head>
<base
href="<%=basePath%>">
<title>My
JSP
'login.jsp'
starting
page</title>
<meta
http-equiv="pragma"
content="no-cache">
<meta
http-equiv="cache-control"
content="no-cache">
<meta
http-equiv="expires"
content="0">
<meta
http-equiv="keywords"
content="keyword1,keyword2,keyword3">
<meta
http-equiv="description"
content="This
is
my
page">
<!--
<link
rel="stylesheet"
type="text/css"
href="styles.css">
-->
</head
<body>
<form
action="/ServletStudy/LoginServlet">
userName:
<input
name="userName"
type="text"/><br/>
password:
<input
name="password"
type="password"/><br/>
<input
type="submit"value="submit"/>
<input
type="reset"value="reset"/>
</form>
</body>
</html>
LoginServlet.java
package
com;
import
java.io.IOException;
import
java.io.PrintWriter;
import
javax.servlet.ServletException;
import
javax.servlet.http.HttpServlet;
import
javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public
class
LoginServlet
extends
HttpServlet
{
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询