谁看看这段代码有什么问题 action=null 文件名为 userregister.jsp

duxd1989 2014-05-28 02:04:48
<%@ page language="java"  import="java.util.*,com.denny.user.vo.*"  pageEncoding="GB18030"%>


<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%
//action 响应内容
//out.println("注册成功!恭喜!");
request.setCharacterEncoding("GBK");
String action = request.getParameter("action");
out.println(action);
if(action != null && action.trim().equals("userregister.jsp")){
out.println(action);
String username = request.getParameter("username");
String password = request.getParameter("userpassword");
UserVo u = new UserVo();
u.setUsername(username);
u.setUserpassword(password);
u.save();
out.println("注册成功!恭喜!");
%>
<center> Register OK</center>
<%
}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'userregister.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">
-->

<script language="javascript" type="text/javascript" src="admin/script/regcheckdata.js">

</script>

</head>

<body>



<form name="form" action="userregister.jsp" method="post" onsubmit="return checkdata()">
<table align = "center" border="1" style="border-collapse: collapse;">
<tr>
<th colspan="2">用户注册</th>
</tr>
<tr>
<td>用户名:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="userpassword" /></td>
</tr>



<tr>
<th class="tdstyle" colspan="2">
<input type="submit" value="注册" />
</th>
</tr>
</table>
</form>
</body>
</html>
...全文
164 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
张含韵 2014-05-30
  • 打赏
  • 举报
回复
好原始的写法,我表示看到jsp页面写java代码的就看不下去
lgq_0714 2014-05-29
  • 打赏
  • 举报
回复
引用 4 楼 duxd1989 的回复:
[quote=引用 2 楼 longtian1213 的回复:] 你表达中没有action这个属性,所以就为nul了! 看样子你是想知道请求来自哪个页面吧! 可以通过请求头部获取!
不是的,我定义action了
 <form name="form" action="userregister.jsp" method="post" onsubmit="return checkdata()">
String action = request.getParameter("action");
out.println(action);
我打印显示结果为空 不知道为什么[/quote] request.getParameter("action");是获取你提交的那个form里面name为action的文本框或者其他控件的值,但是你提交的那个form中没有,所以结果为空。
duxd1989 2014-05-29
  • 打赏
  • 举报
回复
没有人吗 没有人回答吗
duxd1989 2014-05-28
  • 打赏
  • 举报
回复
引用 2 楼 longtian1213 的回复:
你表达中没有action这个属性,所以就为nul了! 看样子你是想知道请求来自哪个页面吧! 可以通过请求头部获取!
不是的,我定义action了
 <form name="form" action="userregister.jsp" method="post" onsubmit="return checkdata()">
String action = request.getParameter("action");
out.println(action);
我打印显示结果为空 不知道为什么
duxd1989 2014-05-28
  • 打赏
  • 举报
回复
引用 1 楼 yufengdxw 的回复:
action="userregister.jsp" ,这样写不对,你struts.xml中你配置的action名是什么?userregister.jsp是result的页面
我没用struts 我想用jsp + javabean 实现用户注册到数据库 我上面贴的这个文件的名称为 userregister.jsp 提交和处理一个页面
S117 2014-05-28
  • 打赏
  • 举报
回复
你表达中没有action这个属性,所以就为nul了! 看样子你是想知道请求来自哪个页面吧! 可以通过请求头部获取!
yufengdxw 2014-05-28
  • 打赏
  • 举报
回复
action="userregister.jsp" ,这样写不对,你struts.xml中你配置的action名是什么?userregister.jsp是result的页面

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧