首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

请好手指教servlet

2012-11-21 
请高手指教servlet我的jsp页面接收不了servlet的发来的数据不知道哪出问题了以下是userModify.jsp%@ page

请高手指教servlet
我的jsp页面接收不了servlet的发来的数据
不知道哪出问题了
以下是
userModify.jsp


<%@ page language="java" import="java.util.*,zls.market.entity.smUser" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
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>
  <title>修改用户</title>
<link type="text/css" rel="stylesheet" href="css/style.css" />
<script type="text/javascript" src="./js/user.js"></script>
</head>
<%--<body onload="setbodydisabled()">

--%>
<body><div class="main">
  <c:set var="user" value="${sessionScope.modifyuser}"></c:set>
<form method="post" >
<input name="option" type="hidden" value="<%=request.getContextPath()%>/UserServlet?option=delete_user" class="input-text" >
<div class="content">
<table class="box">
<tr>
<td class="field">用户编号:</td>
<td><input type="text" name="id" id="textfield" class="text"/ value="${user.id}"> <font color="red">*</font></td>
</tr>
<tr>
<td class="field">用户名称:</td>
<td><input type="text" name="username" class="text" id="textfield2" value="${user.loginname } "/><font color="red">*</font></td>
</tr>
<tr>
<td class="field">用户性别:</td>
<td><select name="sex" id="select">
<c:if test="${user.sex=='女'}">
  <option value="女" selected=true>女</option></c:if>
  <c:if test="${user.sex=='男'}">
  <option value="男" selected=true>男</option></c:if>
  </select>
  </td>
</tr>
<tr>
<td class="field">用户年龄:</td>
<td><input type="text" name="age" class="text" id="textfield2" value="${user.age }"/> <font color="red">*</font></td>
</tr>
<tr>
<td class="field">用户电话:</td>
<td><input type="text" name="mobile" class="text" id="textfield2" value="${user.tel }"/> <font color="red">*</font></td>
</tr>
<tr>
<td class="field">用户地址:</td>
<td><textarea name="address" id="textarea" class="text" cols="45" rows="5">${user.address }</textarea></td>
</tr>
<tr>
<td class="field">用户权限:</td>
<td>
<c:choose>
<c:when test="${user.role=='0' }">
<input type="radio" name="auth" id="auth" value="0" checked="checked"/>普通用户
</c:when>


<c:when test="${user.role=='1' }">
<input type="radio" name="auth" id="auth" value="1" />经理
</c:when>  
</c:choose>
</td>
</tr>
</table>
</div>
<div class="buttons">
<input type="button" id="return" name="button" value="返回" class="input-button" onclick="history.back();" />
<input type="button" id="modify" name="button" value="修改" class="input-button" onclick="return modifying(this);"/>
<input type="submit" id="del" name="submit" value="刪除" class="input-button" onclick="doit('delete_user',${user.id})" />
<input type="button" id="password" name="button" value="修改密碼" class="input-button" />

</div>
</form>
</div>
</body>protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String action = request.getParameter("option");
System.out.println("这是后台的Java类"+action);
if("select_user".equals(action))
doSelect(request, response);
  else if("add_user".equals(action)){
  doAdd(request, response);
  }else if("update_user".equals(action))
  doUpdate(request, response);
  else if("delete_user".equals(action))
  doDelete(request, response);
  else if("select_all".equals(action))
  doSelects(request, response);
  else if("modify_user".equals(action))
  doModidy(request, response);

}
</html>

以下是
userServlet.java
片段
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String action = request.getParameter("option");
System.out.println("这是后台的Java类"+action);
if("select_user".equals(action))
doSelect(request, response);
  else if("add_user".equals(action)){
  doAdd(request, response);
  }else if("update_user".equals(action))
  doUpdate(request, response);
  else if("delete_user".equals(action))
  doDelete(request, response);
  else if("select_all".equals(action))
  doSelects(request, response);
  else if("modify_user".equals(action))
  doModidy(request, response);

}

private void doModidy(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String id=request.getParameter("id");//Integer.valueOf(request.getParameter("id"));
System.out.println("这里是用户Modify页面!获得的user的ID是:"+id);
HttpSession session = request.getSession();
session.setAttribute("modifyuser",userimpl.getUserbyId(Integer.valueOf(id)));
  response.sendRedirect("userModify.jsp");//重定向

}

[解决办法]

 <input type="button" id="return" name="button" value="返回" class="input-button" onclick="history.back();" />


<input type="button" id="modify" name="button" value="修改" class="input-button" onclick="return modifying(this);"/>
<input type="submit" id="del" name="submit" value="刪除" class="input-button" onclick="doit('delete_user',${user.id})" />
<input type="button" id="password" name="button" value="修改密碼" class="input-button" />


最重要的
这几个的js响应代码没有贴出
[解决办法]
<input type="text" name="id" id="textfield" class="text"/ value="${user.id}"> 这行代码是什么问题。。 / 位置放错。 首先看看JSP页面有没有错误!
[解决办法]
首先你能保证modifyuser有值么?
[解决办法]
什么错误啊~~

异常信息贴一下吧~~~

热点排行