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

jsp传参数到servlet中,但提交是用超链接,怎样实现,该怎么处理

2012-05-09 
jsp传参数到servlet中,但提交是用超链接,怎样实现怎样传参数div idright_contentdiv classmembers

jsp传参数到servlet中,但提交是用超链接,怎样实现
怎样传参数
  <div id="right_content"> 
  <div class="members_login">
  <h1>用户登录</h1>
  <div class="login_row">
  <label class="login">用户:</label>
  <input type="text" class="login_input" />
  </div>
  <div class="login_row">
  <label class="login">密码:</label>
  <input type="password" class="login_input" />
  </div>  
  <div class="login_row">
<a href="regist.jsp" class="login_submit">注册</a>
<a href="#" class="login_submit">登陆</a>
  </div>  
  </div>
servlet我已经写好了,public class HandleLogin extends HttpServlet {


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");  
String username = request.getParameter("username");
String userpwd = request.getParameter("userpwd");
 
String sql="select username,userpwd from userInformations ";
Connection conn=DB.getConn();
Statement stmt=DB.stmt(conn);
try {
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
if(rs.getString("username").equals(username)&&rs.getString("userpwd").equals("userpwd"))
{response.sendRedirect("requestpublish.jsp");}
else
{response.sendRedirect("error.jsp");}
}
rs.close();
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
小弟初学,还请各位多多指教!thanks!
 

[解决办法]
<form name="form1" action="***">
<div id="right_content">
<div class="members_login">
<h1>用户登录</h1>
<div class="login_row">
<label class="login">用户:</label>
<input type="text" class="login_input" />
</div>
<div class="login_row">
<label class="login">密码:</label>
<input type="password" class="login_input" />
</div>
<div class="login_row">
<a href="regist.jsp" class="login_submit">注册</a>
<a href="javascript:form1.submit()">登录</a>
</div>
</div>
</form>

热点排行