JAVA WEB开发从数据库中查询到的数据用list怎么在JSP页面整齐的显示出来,请写代码,
2015-05-04 20:25
1036 查看
整齐地输出可以用table。
不知道你用的是原始的jsp还是struts之类的框架,如果是后者,有相应的标记库,直接绑定就可以了。
再不会google些例子程序自己学习下。整齐地输出可以用table。
不知道你用的是原始的jsp还是struts之类的框架,如果是后者,有相应的标记库,直接绑定就可以了。
再不会google些例子程序自己学习下。
标准标签方式
页面头部引入<@ taglib uri="http://java.sun.com/jsp/jstl/core"
prefix="c" />
有好多年不搞Java Web开发了,这几天正好国庆放假,放松之余也有兴趣回头看看Java Web开发技术的基础。
我们都知道,Servlet是Java Web开发的重要基础,但是由于Servlet开发相对繁琐,代码量庞大而且不易维护,美工无法参与界面设计开发等不足,于是就诞生了jsp。jsp是对servlet开发模型的重要升级。有了jsp,Java Web开发技术才真正被广泛使用。
一、Servlet
在Java Web开发当中,新建一个类继承(派生)自HttpServlet类即可创建一个Servlet。
比如:
[java] view
plaincopy
@WebServlet(name="firstServlet",urlPatterns={"/firstServlet"})
public class FirstServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public FirstServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
这段代码是在myeclipse工具当中创建servlet时自动生成的,可以看到我们新建的FirstServlet类继承自HttpServlet。而且又实现了里面的doGet(Get请求时调用的方法)、doPost(Post请求时调用的方法)、init(初始化对象)、destroy(销毁对象)。值得注意的是我们采用了Annotation的方式进行了修饰,即:@WebServlet(name="firstServlet",urlPatterns={"/firstServlet"})。这是servlet3.0开始推荐的,以前采用的方式是在web.xml里面添加servlet和servlet-mapping配置。比如:
[html] view
plaincopy
<servlet>
<servlet-name>firstServlet</servlet-name>
<servlet-class>包名.FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>firstServlet</servlet-name>
<url-pattern>/firstServlet</url-pattern>
</servlet-mapping>
上面的配置有几点需要说明:
1、servlet里面的servlet-class节点需要填写servlet类的完整名称(包名.类名)
2、servlet-mapping下的servlet-name节点的名称要与servlet下的servlet-name节点的名称一致,才能找到。
3、url-pattern下的url要加"/"
启动tomcat,在ie中输入localhost:8080/工程名/firstServet,即可浏览该页面(Get请求)。8080端口是tomcat默认设置的端口号,可以在tomcat/conf/下面的server.xml文件中修改端口号。比如我们修改了默认端口号为8088,重新启动tomcat(加载xml)以后,访问的url即为:localhost:8088/工程名/servlet映射的urlpattern名。
不知道你用的是原始的jsp还是struts之类的框架,如果是后者,有相应的标记库,直接绑定就可以了。
再不会google些例子程序自己学习下。整齐地输出可以用table。
不知道你用的是原始的jsp还是struts之类的框架,如果是后者,有相应的标记库,直接绑定就可以了。
再不会google些例子程序自己学习下。
标准标签方式
页面头部引入<@ taglib uri="http://java.sun.com/jsp/jstl/core"
prefix="c" />
有好多年不搞Java Web开发了,这几天正好国庆放假,放松之余也有兴趣回头看看Java Web开发技术的基础。
我们都知道,Servlet是Java Web开发的重要基础,但是由于Servlet开发相对繁琐,代码量庞大而且不易维护,美工无法参与界面设计开发等不足,于是就诞生了jsp。jsp是对servlet开发模型的重要升级。有了jsp,Java Web开发技术才真正被广泛使用。
一、Servlet
在Java Web开发当中,新建一个类继承(派生)自HttpServlet类即可创建一个Servlet。
比如:
[java] view
plaincopy
@WebServlet(name="firstServlet",urlPatterns={"/firstServlet"})
public class FirstServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public FirstServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
这段代码是在myeclipse工具当中创建servlet时自动生成的,可以看到我们新建的FirstServlet类继承自HttpServlet。而且又实现了里面的doGet(Get请求时调用的方法)、doPost(Post请求时调用的方法)、init(初始化对象)、destroy(销毁对象)。值得注意的是我们采用了Annotation的方式进行了修饰,即:@WebServlet(name="firstServlet",urlPatterns={"/firstServlet"})。这是servlet3.0开始推荐的,以前采用的方式是在web.xml里面添加servlet和servlet-mapping配置。比如:
[html] view
plaincopy
<servlet>
<servlet-name>firstServlet</servlet-name>
<servlet-class>包名.FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>firstServlet</servlet-name>
<url-pattern>/firstServlet</url-pattern>
</servlet-mapping>
上面的配置有几点需要说明:
1、servlet里面的servlet-class节点需要填写servlet类的完整名称(包名.类名)
2、servlet-mapping下的servlet-name节点的名称要与servlet下的servlet-name节点的名称一致,才能找到。
3、url-pattern下的url要加"/"
启动tomcat,在ie中输入localhost:8080/工程名/firstServet,即可浏览该页面(Get请求)。8080端口是tomcat默认设置的端口号,可以在tomcat/conf/下面的server.xml文件中修改端口号。比如我们修改了默认端口号为8088,重新启动tomcat(加载xml)以后,访问的url即为:localhost:8088/工程名/servlet映射的urlpattern名。
相关文章推荐
- 在Action中查询出SQL SERVER表的数据,返回一个list。怎么在JSP页面中使用Struts标签,显示出表中的内容?(转)
- 请问如何在Web页面中点击一个button之后,用jsp从数据库中读取数据显示到表格里
- JAVA 使数据库内的每条数据显示在JSP页面上
- 使用该JavaBean可以将数据在JSP页面中以表格的形式显示出来,并具有动态排序、动态生成查询、自动分页功能
- JSP中如何 循环显示 数据库中的数据到list.jsp页面 (转载)
- JSP中如何 循环显示 数据库中的数据到list.jsp页面 (转载)
- myecilpse +TOMCAT+web:jsp向mysql添加数据,查询在jsp页面显示
- 怎么在后台将数据库中数据查询出来并分页显示在客户端?!!!
- 将数据库里面的数据遍历出来显示在jsp页面
- javaweb开发jsp页面一次性保存多条数据,批量保存数据!
- java中对list分页并显示数据到页面实例代码
- 用java将查询到的数据显示到在jsp页面(查询所有及查询一条记录)
- java怎么把图片以base64字节存入数据库,并将其显示到jsp页面上
- javaweb --- jsp页面遍历list<map>类型的数据
- JSP中如何 循环显示 数据库中的数据到list.jsp页面 (转载)
- 数据库中的记录通过servlet回显到jsp页面中(连接数据库或者查询參照:对数据进行增删改查)
- java web程序升级jsp页面缓存无法显示最新的内容
- WEB开发中遇到的困难,controller方法对应的url显示不出来页面
- 利用hibernate的session查询数据库,而且在jsp页面显示表内容的方法
- 【Servlet】在Servlet3.0中利用json+ajax把数据库查询出来的数据推向前台显示,无额外的json解析包