java 我做了简单的用户注册系统,现在我要把用户注册的信息显示在jsp页面上,该怎么写?
我记得老师好像在显示的jsp?这是我的部分servlet类代码(变量的定义在图片里):if(b){notice="添加用户成功!";UserBeanuser=ud.get...
我记得老师好像在显示的jsp?这是我的部分servlet类代码(变量的定义在图片里):
if (b) {
notice = "添加用户成功!";
UserBean user=ud.getOneUser(username);
request.setAttribute("abc",username);
send="Chenggong.jsp";
}
我该怎么写Chenggong.jsp的代码才可以显示该注册用户信息?
具体的代码哦。
谢谢! 展开
if (b) {
notice = "添加用户成功!";
UserBean user=ud.getOneUser(username);
request.setAttribute("abc",username);
send="Chenggong.jsp";
}
我该怎么写Chenggong.jsp的代码才可以显示该注册用户信息?
具体的代码哦。
谢谢! 展开
4个回答
展开全部
//这句是用response跳转到你要跳转的页面,并将值usename传递过去,
response.sendRedirect("你要跳转的页面.jsp?usename="+usename);
//在你要跳转的页面,就用request获取就行了。
<h1><%=request.getParameter("usename")%>!欢迎你的登陆!</h1>
具体的话,应该是这么写,其实也还有其他的方法,我就只记得这一个了,希望能帮到你
response.sendRedirect("你要跳转的页面.jsp?usename="+usename);
//在你要跳转的页面,就用request获取就行了。
<h1><%=request.getParameter("usename")%>!欢迎你的登陆!</h1>
具体的话,应该是这么写,其实也还有其他的方法,我就只记得这一个了,希望能帮到你
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在JSP页里取到你的UserBean对象
<%=us.getUserName()%>
这样
<%=us.getUserName()%>
这样
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
${abc}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这是我的代码你看了就懂了,方法是一样的
HandleRegister.java
package bean;
import bean.BaseDAO;
import bean.Regiser;
import bean.*;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HandleRegister extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("gb2312");
BaseDAO bd = new BaseDAO();
Regiser reg = new Regiser();
request.setAttribute("regiser",reg);
String logname=request.getParameter("logname").trim();
String password=request.getParameter("password").trim();
String email=request.getParameter("email").trim();
String phone=request.getParameter("phone").trim();
String message=request.getParameter("message");
String backNews="";
try{String insert="insert into member values ('"+logname+"','"+password+"','"+phone+"','"+email+"','"+message+"')";
int n=bd.Exec(insert);
if(n!=0){
backNews="注册成功";
reg.setBackNews(backNews);
reg.setLogname(logname);
reg.setEmail(email);
reg.setPassword(password);
reg.setMessage(message);
reg.setPhone(phone);
}
}
catch(Exception exp){
backNews="该用户名已被使用";
reg.setBackNews(backNews);
}
RequestDispatcher dispather=request.getRequestDispatcher("showRegister.jsp");
dispather.forward(request, response);
}
}
显示页面showRegister.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="bean.Regiser"%>
<jsp:useBean id="regiser" type="bean.Regiser" scope="request"/>
<%
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>My JSP 'showRegister.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">
-->
</head>
<body><div align="center"><h4><jsp:getProperty name="regiser" property="backNews"/></h4><br>
<form id="form" name="form" method="post" >
<table width="256" border="1">
<tr>
<td width="85">用户名:</td>
<td width="168"><jsp:getProperty name="regiser" property="logname"/></td>
</tr>
<tr>
<td>密码:</td>
<td><jsp:getProperty name="regiser" property="password"/></td>
</tr>
<tr>
<td>电话:</td>
<td><jsp:getProperty name="regiser" property="phone"/></td>
</tr>
<tr>
<td>邮箱:</td>
<td><jsp:getProperty name="regiser" property="email"/></td>
</tr>
<tr>
</tr>
<tr>
<td width="85">简介:</td>
<td width="168" height="100">
<jsp:getProperty name="regiser" property="message"/> </td>
</tr>
</table>
</form>
</body>
</html>
其中还有俩个java文件,一个是存放模型的get和set方法的,一个是表单。你既然写到这里了你应该懂得。我就不贴出来了
也可以用${regiser.logname }直接调用,显示出来,这个就不详细解释
HandleRegister.java
package bean;
import bean.BaseDAO;
import bean.Regiser;
import bean.*;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HandleRegister extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("gb2312");
BaseDAO bd = new BaseDAO();
Regiser reg = new Regiser();
request.setAttribute("regiser",reg);
String logname=request.getParameter("logname").trim();
String password=request.getParameter("password").trim();
String email=request.getParameter("email").trim();
String phone=request.getParameter("phone").trim();
String message=request.getParameter("message");
String backNews="";
try{String insert="insert into member values ('"+logname+"','"+password+"','"+phone+"','"+email+"','"+message+"')";
int n=bd.Exec(insert);
if(n!=0){
backNews="注册成功";
reg.setBackNews(backNews);
reg.setLogname(logname);
reg.setEmail(email);
reg.setPassword(password);
reg.setMessage(message);
reg.setPhone(phone);
}
}
catch(Exception exp){
backNews="该用户名已被使用";
reg.setBackNews(backNews);
}
RequestDispatcher dispather=request.getRequestDispatcher("showRegister.jsp");
dispather.forward(request, response);
}
}
显示页面showRegister.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="bean.Regiser"%>
<jsp:useBean id="regiser" type="bean.Regiser" scope="request"/>
<%
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>My JSP 'showRegister.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">
-->
</head>
<body><div align="center"><h4><jsp:getProperty name="regiser" property="backNews"/></h4><br>
<form id="form" name="form" method="post" >
<table width="256" border="1">
<tr>
<td width="85">用户名:</td>
<td width="168"><jsp:getProperty name="regiser" property="logname"/></td>
</tr>
<tr>
<td>密码:</td>
<td><jsp:getProperty name="regiser" property="password"/></td>
</tr>
<tr>
<td>电话:</td>
<td><jsp:getProperty name="regiser" property="phone"/></td>
</tr>
<tr>
<td>邮箱:</td>
<td><jsp:getProperty name="regiser" property="email"/></td>
</tr>
<tr>
</tr>
<tr>
<td width="85">简介:</td>
<td width="168" height="100">
<jsp:getProperty name="regiser" property="message"/> </td>
</tr>
</table>
</form>
</body>
</html>
其中还有俩个java文件,一个是存放模型的get和set方法的,一个是表单。你既然写到这里了你应该懂得。我就不贴出来了
也可以用${regiser.logname }直接调用,显示出来,这个就不详细解释
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询