2, 超链接:<a href=""></a>
3, 网页后退:οnclick="history.back()"
4, 单击事件:οnclick="location.href='toaddcost.do'"
5, οnclick="location.href='toupdatecost.do?id=${c.costId}'"
网页链接到服务器,toupdatecost.do是相对路径,
?id=${c.costId}'用路径传了一个参数,可以在servlet里用req.getAttibute("id")接收
6, <script language="javascript" type="text/javascript">
function deleteFee(id) {
var r = window.confirm("确定要删除此资费吗?")
if(r){
location.href='delete.do?costId='+id
}
}
</script>
<input type="button" value="删除" class="btn_delete" οnclick="deleteFee(${c.costId })" />
单击删除按钮,调用deleteFee(),调用确认框confirm()方法,
如果点击确认,改变当前浏览的网址
7.<img src="createimg.do" οnclick="this.setAttribute('src','createimg.do?x='+Math.random())" alt="验证码" title="点击更换" />
单击改变验证码图片的src属性,在后面增加随机参数的目的,是为了让浏览器误以为路径发生了变化。
8. <form action="" method="post">
<a href="javascript:document.forms[0].submit()"><a>
<form>
html页面跳转到servlet是通过提交form的action到servlet的一个处理入口实现的。1、页面html代码:
<html>
<body>
<form ACTION="./post2" METHOD="POST">
<input name="name" type="text" id="name"/>
<input name="send" type="submit" value="send"/>
</form>
</body>
<html>
2、在servlet中定义的处理post请求的方法:
import java.io.IOException
import java.io.PrintWriter
import javax.servlet.http.*
public class post2 extends HttpServlet{
protected void doDo(HttpServletRequest request,HttpServletResponse response)
throws IOException{
获取form表单参数:
String name = request.getParameter("name")
response.setContentType("text/html")
PrintWriter out = response.getWriter()
out.println("<HTML><BODY>")
out.println("<H2>hello "+name+"</H2>")
out.println("<BR><BR>")
out.println("info:")
out.println("<BR><BR>")
out.println("<H2>metoda GET</H2>")
out.println("<BR><BR>")
out.println("SERVER_NAME="+request.getServerName()+"<BR>")
out.println("REQUEST_METHOD="+request.getMethod()+"<BR>")
out.println("QUERY_STRING="+request.getQueryString()+"<BR>")
out.println("REMOTE_HOST="+request.getRemoteHost()+"<BR>")
out.println("REMOTE_ADDR="+request.getRemoteAddr())
out.println("</BODY></HTML>")
}
@Override
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException {
doDo(request,response)
}
@Override
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException {
doDo(request,response)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)