JSP新闻发布

index.jsp`

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

	<form action = "release.jsp" methon = post>
		<table>
			<tr>
				<td>
					<b>新闻发布</b>
				</td>
		</tr>
		<tr>
			<td>标题</td>
			<td>
				<input type = "text" name = "title" >
			</td>
		</tr>
		<tr>
			<td>内容</td>
			<td>
				<input type = "text" name = "content" >
			</td>
		</tr>
		<tr>
			<td>
				<input type = "submit" value = "提交">
			</td>
		</tr>
		</table>
	
	
	</form>
</body>
</html>

release.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="newsRelease.encStr"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<div align = "center">
		<%
			String text = request.getParameter("title");
			String content = request.getParameter("content");
		%>
		<table>
			<td>
				标题是:<%=text %>
				内容是:<%=content %>
			</td>
		</table>
	</div>
<jsp:useBean id="aNews" class="newsRelease.News"></jsp:useBean>
<jsp:setProperty property="*" name="aNews"/>
<h1>标题:
<%=encStr.getStr(aNews.getTitle())  %>
</h1>
<h4>
内容:
<%=encStr.getStr(aNews.getContent()) %>
</h4>
</body>
</html>

dataTime.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="1">
<title>Insert title here</title>
</head>
<body>
<%=new Date() %>
<jsp:useBean id="aDate" class="newsRelease.DateTime"></jsp:useBean>
<jsp:getProperty property="dateTime" name="aDate"/>
<jsp:getProperty property="week" name="aDate"/>
</body>
</html>

创建newselease包
encStr类用于解决乱码

package newsRelease;

import java.io.UnsupportedEncodingException;

public class encStr {

	public static String getStr(String str){
		String nStr="";
		try {
			nStr = new String(str.getBytes("ISO8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return nStr;
		
	}
}

news类

package newsRelease;

public class News {
	private String title;
	private String content;
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	
}

datatime类 用于显示时间

package newsRelease;

import java.text.SimpleDateFormat;
import java.util.*;

public class DateTime {
	private Calendar calendar= Calendar.getInstance();
	private String week;
	public String getDateTime(){
		Date curDate=calendar.getTime();
		SimpleDateFormat sdf=new SimpleDateFormat("yyy年MM月dd日  HH时mm分ss秒");
		return sdf.format(curDate);
	}
	
	public String getWeek(){
		String[] weeks={"周日","周一","周二","周三","周四","周五","周六"};
		int intWeek=calendar.get(Calendar.DAY_OF_WEEK);
		week= weeks[intWeek-1];
		return week;
	}
	
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值