Четверг
09-05-2024
04:18
Главная страница
Каталог статей
Информист Приветствую Вас Гость | RSS
Регистрация
Вход
Меню сайта

Категории каталога
Delphi [3]
C++ [5]
Java [28]
программирование на Java
Assembler [4]
Алгоритмы на ассме
C# [1]
Eclipse [1]

Наш опрос
Насколько вам понравился этот сайт
Всего ответов: 545

Копилка
Если вам понравился наш сайт или вы нашли полезную информацию, то у вас есть возможность отблагодарить администрацию.

Начало » Статьи » Programming » Java

Основы веб-программирования
Сервлет:

 package my.sample.servlet; 
   
 import java.io.IOException; 
 import java.util.List; 
   
 import javax.servlet.ServletException; 
 import javax.servlet.http.HttpServlet; 
 import javax.servlet.http.HttpServletRequest; 
 import javax.servlet.http.HttpServletResponse; 
   
 import my.sample.dao.UserDao; 
 import my.sample.dao.impl.UserDaoImpl; 
 import my.sample.entity.User; 
   
 public class UserList extends HttpServlet { 
     private static final long serialVersionUID = -8188437758039848236L; 
   
     private  UserDao userDao = new UserDaoImpl(); 
       
     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
         execute(request, response); 
     } 
   
     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
         execute(request, response); 
     } 
   
     private void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
         List theUserList = userDao.getUsersOrderByName(); 
         request.setAttribute("userList", theUserList); 
         request.getRequestDispatcher("/WEB-INF/jsp/user-list.jsp").forward(request, response); 
         return; 
     } 
 }
JSP:

 <?xml version="1.0" encoding="UTF-8" ?> 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 
 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
 <html xmlns="http://www.w3.org/1999/xhtml"> 
 <head> 
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
 <link rel="stylesheet" type="text/css" href="./css/commons.css" /> 
 <title>User room</title> 
 </head> 
 <body> 
 <%@include file="/WEB-INF/jsp/include/header.jsp" %> 
 <table style=" border-style: solid; border-width:1px; width: 600px; border-collapse: collapse;"> 
 <thead> 
 <tr style="background-color: gray;"> 
 <td style="width: 30px;">id</td> 
 <td style="width: 80px;">name</td> 
 <td style="width: 80px;">role</td> 
 <td></td> 
 <td style="width: 80px;">action</td> 
 <td style="width: 80px;">action</td> 
 </tr> 
 </thead>  
 <c:forEach var="user" items="${userList}"> 
     <tr> 
         <td>${user.id}</td> 
         <td><c:out value="${user.name}" /></td> 
         <td></td> 
         <td><c:out value="${user.role}" /></td> 
         <td><a href="./kill-user.html?id=${theUser.id}">delete</a></td> 
         <td><a href="./edit-user.html?id=${theUser.id}">edit</a></td> 
     </tr> 
 </c:forEach> 
 </table> 
 </body> 
 </html>


Источник: http://www.javatalks.ru/ftopic12590-0-asc-0.php
Категория: Java | Добавил: Judge (23-02-2010)
Просмотров: 1615 | Рейтинг: 0.0 |

Всего комментариев: 0
Имя *:
Email *:
Код *:
Форма входа

Поиск по каталогу
Яндекс


Поиск по Информисту

Наша кнопка


Друзья сайта

Статистика


Copyright MyCorp © 2006Сайт создан в системе uCoz