发布网友 发布时间:2022-04-20 20:37
共4个回答
懂视网 时间:2022-04-29 21:16
错误:url通过get传递时汉字出错
解决:url通过get传递时汉字会乱码,
1.String name1=request.getParameter("name");
String name = new String(name1.getBytes("ISO-8859-1"),"gbk");
2.通过post传递参数
错误:url通过get传递有空格时错误
解决:url通过get传递,是不会传递空格,只会得到空格前的数据,所以最好把空格该一下
实现确认删除键
在.js文件中写函数:
function delecheck()
{
if (!confirm("确定要删除?"))
{
window.event.returnValue = false;
}
}
在jsp文件中加上:
<script language="javascript" src=js/check.js></script>
<a href="。。?method=。。&。。=。。" onClick="delecheck()">删除操作员
方法:输入框输入提示代码
鼠标点到必填项则为空,若未填必填项,且鼠标在其他地方时,显示“输入关键字”
<input name="keyword" type="text" value="请输入关键字" onFocus="this.value=‘‘" onBlur="if(!value){value=defaultValue;}">
用按钮来实现跳转页面(使用onclick跳转到其他页面/跳转到指定url):
1.在本窗口打开:
如果是本页显示可以直接用location,方法如下:
①onclick="javascript:window.location.href=‘URL‘"
②onclick="location=‘URL‘"
③onclick="window.location.href=‘URL?id=11‘"
如果页面中有frame可以将在location前面添加top.mainframe.frams[‘right_frame‘].location
例子:
<input type="submit" name="name" value="定制" onClick="javascript:window.location.href=‘index.jsp‘"><hr>
<input type="submit" name="name" value="定制" onclick="window.location.href=‘Lll?method=tuxiang&id=11‘"><hr>
2.新建窗口
window.open(‘index.jsp‘)
例子:
<input type="submit" name="name" value="定制" onClick="window.open(‘index.jsp‘)"><hr>
返回上一页:
用按钮实现:<input type="button" name="Submit" onclick="javascript:history.back(-1);" value="返回上一页"><br>
不用按钮:<a href="javascript:;" onClick="javascript :history.back(-1);">返回上一页</a>
用图片做:<a href="javascript :;" onClick="javascript :history.back(-1);"><img src="图片路径" border="0" title="返回上一页"></a>
java+jsp+mysql网页制作总结(2)
标签:
热心网友 时间:2022-04-29 18:24
运行环境 vista+tomcat+mysql
reg.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>注册新用户</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">
</head>
<body>
<form name="form1" method="post" action="\file\WebRoot\insert.jsp">
<table width="500" border="0" align="center" bgcolor="#aad0d7" height="250">
<tbody>
<tr><td valign="top"><br></td><td valign="top"><br></td></tr><<tr>
<td>姓 名 <br></td>
<td> <input type="text" name="username"></td></tr>
<tr>
<td>邮 箱 <br></td>
<td> <input type="text" name="usermail"></td></tr>
<tr>
<td>密 码 <br></td>
<td> <input type="password" name="password"></td></tr>
<tr>
<td>密码确认 <br></td>
<td> <input type="password" name="password2"></td></tr>
<tr>
<td> </td>
<td> </td></tr>
<tr>
<td> <input type="submit" value="提交" name="button"></td>
<td> <input type="reset" value="重置" name="button2"></td></tr>
</tbody></table>
</form>
</body>
</html>
insert.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="gbk"%>
<%
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>insert</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">
</head>
<body>
<%
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager
.getConnection(
"jdbc:mysql://localhost:3306/file?useUnicode=true&?characterEncoding=gbk",
"root", "xxxxxxx");
String UserName = request.getParameter("username");
String UserMail = request.getParameter("usermail");
String UserPassword = request.getParameter("password");
String sql = "insert into tbluser (UserName,UserMail,UserPassword)values(?,?,?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, UserName);
pstmt.setString(2, UserMail);
pstmt.setString(3, UserPassword);
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
out.println("aaaaa");
}
%>
</body>
</html>
热心网友 时间:2022-04-29 19:42
HI我。
热心网友 时间:2022-04-29 21:17
download from many web site. it's very easy.