??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品96久久久久久,欧美日韩免费高清,污视频免费在线观看http://www.aygfsteel.com/Crying/category/25483.html????????, ??????????握! zh-cnThu, 10 Apr 2008 11:34:59 GMTThu, 10 Apr 2008 11:34:59 GMT60jsp 防盗链(转)(j)http://www.aygfsteel.com/alex/archive/2007/03/13/103458.htmlhttp://www.aygfsteel.com/Crying/articles/191778.htmlCryingCryingThu, 10 Apr 2008 02:34:00 GMThttp://www.aygfsteel.com/Crying/articles/191778.htmlhttp://www.aygfsteel.com/Crying/comments/191778.htmlhttp://www.aygfsteel.com/Crying/articles/191778.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/191778.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/191778.html<html>
  
<head><title>Simple jsp page</title></head>
  
<body>Place your content here

  here is index jsp
    get header info
  
<href="a.jsp">a.jsp</a>
  
</body>
</html>
a.jsp面
<html>
  
<head><title>Simple jsp page</title></head>
  
<body>Place your content here

  here is a. jsp
    get header info
  
<%=request.getHeader("Referer")%>
  
<%if(null == request.getHeader("Referer") || request.getHeader("Referer").indexOf("yourdomain.com"< 0){%>
     做h要厚?br />   
<%}else{%>
  合法讉K
  
<%}%>
  
</body>
</html>



Crying 2008-04-10 10:34 发表评论
]]>
获得IPhttp://www.aygfsteel.com/Crying/articles/190528.htmlCryingCryingThu, 03 Apr 2008 01:31:00 GMThttp://www.aygfsteel.com/Crying/articles/190528.htmlhttp://www.aygfsteel.com/Crying/comments/190528.htmlhttp://www.aygfsteel.com/Crying/articles/190528.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/190528.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/190528.htmlString IP = httpRequest.getHeader("x-forworded-for");
  if (IP != null && IP.length() != 0) {
   while ((IP != null) && (IP.equals("unknow"))) {

    IP = httpRequest.getHeader("x-forworded-for");
   }
  }

  if (IP == null || IP.length() == 0) {
   IP = httpRequest.getHeader("Proxy-Client-IP");
  }

  if (IP == null || IP.length() == 0) {
   IP = httpRequest.getHeader("WL-Proxy-Client-IP");
  }

  if (IP == null || IP.length() == 0) {
   IP = httpRequest.getRemoteAddr();
  }
  // 得到讉K者所在网D?br />  String  subIP = IP.substring(0, IP.lastIndexOf("."));
  
  System.out.println("真实的IP地址Q? + IP+"|段是:(x)"+subIP);



Crying 2008-04-03 09:31 发表评论
]]>
JSP操作文ghttp://www.aygfsteel.com/Crying/articles/185147.htmlCryingCryingMon, 10 Mar 2008 09:28:00 GMThttp://www.aygfsteel.com/Crying/articles/185147.htmlhttp://www.aygfsteel.com/Crying/comments/185147.htmlhttp://www.aygfsteel.com/Crying/articles/185147.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/185147.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/185147.htmld文g
两种方式Q一U利用ServletContext 来读取上下文中的资源Q另一U用java.io.FileReader
来读取Q何位|上的文件?br /> ServletContext d文g
<%@ page contentType="text/html; charset=gb2312" import="java.io.*"%>
<%
try
{
//使用ServletContext 装入文g资源
//q里的path参数必须在上下文环境中,所以必M“/“开?br /> //使用InputStreamQ没有用缓冲输入流Q效率低
InputStream in=getServletContext().getResourceAsStream("/file.txt");
String file="";
int temp=0;
while((temp=in.read())!=-1)
{
file+=(char)temp;
}
//关闭输入?br /> in.close();
//使用InputStream对象Q在d文g内容后因该进行重~码Q否则会(x)产生q
out.println(new String(file.getBytes("iso-8859-1")));
out.flush();
}
catch(Exception e)
{
out.println(e);
e.printStackTrace();
}
%>
改进后:(x)
<%@ page contentType="text/html; charset=gb2312" import="java.io.*" buffer="64kb"%>
<%
try
{
InputStream in=getServletContext().getResourceAsStream("/file.txt");
String file="";
String temp="";
//效率提升Q而且不用担心(j)q问题
BufferedReader buffer=new BufferedReader(new InputStreamReader(new BufferedInputStream(in)));
while((temp=buffer.readLine())!=null)
{
file+=temp;
}
buffer.close();
in.close();
out.println(file);
out.flush();
}
catch(Exception e)
{
out.println(e);
e.printStackTrace();
}
%>
使用FileReaderd文gQ?/span>
<%@ page contentType="text/html; charset=gb2312" import="java.io.*" buffer="64kb"%>
<%
try
{
BufferedReader in=new BufferedReader(new FileReader("c:\\UserSession.java"));
String file="";
String temp="";
while((temp=in.readLine())!=null)
{
file+=temp;
}
in.close();
out.println(file);
out.flush();
}
catch(Exception e)
{
out.println(e);
e.printStackTrace();
}
%>


写入内容到文?/span>
使用FileWriter 对象写入文g
<%@ page contentType="text/html; charset=gb2312" import="java.io.*"%>
<html>
<body>
<%
request.setCharacterEncoding("gb2312");
String content=request.getParameter("content");
%>
<%
try
{
PrintWriter writer= new PrintWriter(new BufferedWriter(new
FileWriter("c:\\foo.out",true)));
writer.write(content);
writer.close();
out.println("已经把内容写入到c:\\foo.out");
}
catch(Exception e)
{
out.println(e);
e.printStackTrace();
}
%>
<form action="writeFile.jsp" method=post>
<textarea name=content cols=20 rows=5></textarea><br>
<input type=submit value=提交>
</form>
</body>
</html>

Crying 2008-03-10 17:28 发表评论
]]>
dispatchActionhttp://www.aygfsteel.com/Crying/articles/184766.htmlCryingCryingSat, 08 Mar 2008 15:32:00 GMThttp://www.aygfsteel.com/Crying/articles/184766.htmlhttp://www.aygfsteel.com/Crying/comments/184766.htmlhttp://www.aygfsteel.com/Crying/articles/184766.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/184766.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/184766.html
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
 
<html>
 <head>
  <title>JSP for Add_UpdateForm form</title>
 </head>
 <body>
 <h1>d面</h1>
  <html:form action="/add_Update.do?methods=add">
   password : <html:password property="password"/><html:errors property="password"/><br/>
   name : <html:text property="name"/><html:errors property="name"/><br/>
   <html:submit /><html:cancel/>
  </html:form>
 </body>
</html>



<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
 
<html>
 <head>
  <title>JSP for Add_UpdateForm form</title>
 </head>
 <body>
 <h1>修改面</h1>
  <html:form action="/add_Update.do?methods=update">
   password : <html:password property="password"/><html:errors property="password"/><br/>
   name : <html:text property="name"/><html:errors property="name"/><br/>
   <html:submit/><html:cancel/>
  </html:form>
 </body>
</html>
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111

package com.yourcompany.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;


public class Add_UpdateAction extends DispatchAction {
 
 public ActionForward add(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {
    return mapping.findForward("addOk");
 }
 public ActionForward update(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {
  return mapping.findForward("updateOk");
}
}


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
  <data-sources />
  <form-beans >
    <form-bean name="add_UpdateForm" type="com.yourcompany.struts.form.Add_UpdateForm" />

  </form-beans>

  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action
      attribute="add_UpdateForm"
      input="/add.jsp"
      name="add_UpdateForm"
      parameter="methods"
      path="/add_Update"
      scope="request"
      type="com.yourcompany.struts.action.Add_UpdateAction">
      <forward name="addOk" path="/addOk.jsp" />
      <forward name="updateOk" path="/updateOk.jsp" />
    </action>

  </action-mappings>

  <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>





Crying 2008-03-08 23:32 发表评论
]]>
struts?lt;html:link>标签能够触发struts-config.xml里头的action吗?http://www.aygfsteel.com/Crying/articles/184762.htmlCryingCryingSat, 08 Mar 2008 15:09:00 GMThttp://www.aygfsteel.com/Crying/articles/184762.htmlhttp://www.aygfsteel.com/Crying/comments/184762.htmlhttp://www.aygfsteel.com/Crying/articles/184762.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/184762.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/184762.html1.<html:link action="/xxx">q接</html:link >
2..<html:link page="/xxx.do">q接</html:link >
带参?
1.<html:link action="/xxxQ参数名=xxx">q接</html:link >
2..<html:link page="/xxx.do?参数?xxx">q接</html:link >

Crying 2008-03-08 23:09 发表评论
]]>
验证? Q世界上最差的Q?/title><link>http://www.aygfsteel.com/Crying/articles/164025.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Thu, 29 Nov 2007 08:31:00 GMT</pubDate><guid>http://www.aygfsteel.com/Crying/articles/164025.html</guid><wfw:comment>http://www.aygfsteel.com/Crying/comments/164025.html</wfw:comment><comments>http://www.aygfsteel.com/Crying/articles/164025.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/Crying/comments/commentRss/164025.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/Crying/services/trackbacks/164025.html</trackback:ping><description><![CDATA[<p><%@ page language="java" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" <br />      contentType="image/jpeg" pageEncoding="UTF-8"%></p> <p><br /> <%  //讄面不缓?br />    response.setHeader("Pragma","No-cache");<br />    response.setHeader("Cahce-Control","no-cache");<br />    response.setDateHeader("Expires",0);<br />    //在内存(sh)创徏囄<br />    int width=60,height=20;<br />    BufferedImage image=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);<br />    //获取囑Ş上下?br />    Graphics g= image.getGraphics();<br />    //生成随机c?br />    Random random= new Random();<br />    //讄背景颜色<br />    g.setColor(new Color(160,200,100));<br />    g.fillRect(0,0,width,height);<br />    //讄字体<br />    g.setFont(new Font("Times New Roman",Font.PLAIN,18));<br />    //随机产生50条干扰线Q囑Ş中的验证码不易被其他的程序探到<br />     g.setColor(new Color(160,200,200));<br />    for(int i=0;i<50;i++)<br />    {<br />      int x=random.nextInt(width);<br />      int y=random.nextInt(height);<br />      int x1=random.nextInt(width);<br />      int y1=random.nextInt(height);<br />      g.drawLine(x,y,x+x1,y+y1);<br />    }<br />    //随机产生验证码(4为数字)(j)<br />    String sRand="";<br />    for(int i=0;i<4;i++)<br />    {<br />      String rand=String.valueOf(random.nextInt(10));<br />      sRand+=rand;<br />      //验证码昄到图?br />      g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));<br />      g.drawString(rand,13*i+6,16);<br />    }<br />    session.setAttribute("rand",sRand);  //////生的验证码存储到sesson?br />    g.dispose();<br />    ImageIO.write(image,"JPEG",response.getOutputStream());<br />    out.clear(); //***********<br />    out=pageContext.pushBody();//**********<br />  %><br /> *********************************************************************<br /> <img src="yanzhengma.jsp" id="CheckCodeimg" title="看不清请点击囄Q?/><html:errors property="yanzhengma"/>&nbsp;<br /> <a href="#" onclick="document.getElementById('CheckCodeimg').src='yanzhengma.jsp';">看不清?</a><br/></p> <img src ="http://www.aygfsteel.com/Crying/aggbug/164025.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/Crying/" target="_blank">Crying</a> 2007-11-29 16:31 <a href="http://www.aygfsteel.com/Crying/articles/164025.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>contentTypecdhttp://www.aygfsteel.com/Crying/articles/162786.htmlCryingCryingSat, 24 Nov 2007 02:00:00 GMThttp://www.aygfsteel.com/Crying/articles/162786.htmlhttp://www.aygfsteel.com/Crying/comments/162786.htmlhttp://www.aygfsteel.com/Crying/articles/162786.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/162786.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/162786.html
                                                                  Response.ContentType

名称 cd
ai application/postscript
aif audio/x-aiff
aifc audio/x-aiff
aiff audio/x-aiff
asc text/plain
au audio/basic
avi video/x-msvideo
bcpio application/x-bcpio
bin application/octet-stream
bmp image/bmp
cdf application/x-netcdf
class application/octet-stream
cpio application/x-cpio
cpt application/mac-compactpro
csh application/x-csh
css text/css
dcr application/x-director
dir application/x-director
djv image/vnd.djvu
djvu image/vnd.djvu
dll application/octet-stream
dms application/octet-stream
doc application/msword
dvi application/x-dvi
dxr application/x-director
eps application/postscript
etx text/x-setext
exe application/octet-stream
ez application/andrew-inset
gif image/gif
gtar application/x-gtar
hdf application/x-hdf
hqx application/mac-binhex40
htm text/html
html text/html
ice x-conference/x-cooltalk
ief image/ief
iges model/iges
igs model/iges
jpe image/jpeg
jpeg image/jpeg
jpg image/jpeg
js application/x-javascript
kar audio/midi
latex application/x-latex
lha application/octet-stream
lzh application/octet-stream
m3u audio/x-mpegurl
man application/x-troff-man
me application/x-troff-me
mesh model/mesh
mid audio/midi
midi audio/midi
mif application/vnd.mif
mov video/quicktime
movie video/x-sgi-movie
mp2 audio/mpeg
mp3 audio/mpeg
mpe video/mpeg
mpeg video/mpeg
mpg video/mpeg
mpga audio/mpeg
ms application/x-troff-ms
msh model/mesh
mxu video/vnd.mpegurl
nc application/x-netcdf
oda application/oda
pbm image/x-portable-bitmap
pdb chemical/x-pdb
pdf application/pdf
pgm image/x-portable-graymap
pgn application/x-chess-pgn
png image/png
pnm image/x-portable-anymap
ppm image/x-portable-pixmap
ppt application/vnd.ms-powerpoint
ps application/postscript
qt video/quicktime
ra audio/x-realaudio
ram audio/x-pn-realaudio
ras image/x-cmu-raster
rgb image/x-rgb
rm audio/x-pn-realaudio
roff application/x-troff
rpm audio/x-pn-realaudio-plugin
rtf text/rtf
rtx text/richtext
sgm text/sgml
sgml text/sgml
sh application/x-sh
shar application/x-shar
silo model/mesh
sit application/x-stuffit
skd application/x-koan
skm application/x-koan
skp application/x-koan
skt application/x-koan
smi application/smil
smil application/smil
snd audio/basic
so application/octet-stream
spl application/x-futuresplash
src application/x-wais-source
sv4cpio application/x-sv4cpio
sv4crc application/x-sv4crc
swf application/x-shockwave-flash
t application/x-troff
tar application/x-tar
tcl application/x-tcl
tex application/x-tex
texi application/x-texinfo
texinfo application/x-texinfo
tif image/tiff
tiff image/tiff
tr application/x-troff
tsv text/tab-separated-values
txt text/plain
ustar application/x-ustar
vcd application/x-cdlink
vrml model/vrml
wav audio/x-wav
wbmp image/vnd.wap.wbmp
wbxml application/vnd.wap.wbxml
wml text/vnd.wap.wml
wmlc application/vnd.wap.wmlc
wmls text/vnd.wap.wmlscript
wmlsc application/vnd.wap.wmlscriptc
wrl model/vrml
xbm image/x-xbitmap
xht application/xhtml+xml
xhtml application/xhtml+xml
xls application/vnd.ms-excel
xml text/xml
xpm image/x-xpixmap
xsl text/xml
xwd image/x-xwindowdump
xyz chemical/x-xyz
zip application/zip


Crying 2007-11-24 10:00 发表评论
]]>
打印l(f)ist,hashmap?qing)删?/title><link>http://www.aygfsteel.com/Crying/articles/153982.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Thu, 18 Oct 2007 11:10:00 GMT</pubDate><guid>http://www.aygfsteel.com/Crying/articles/153982.html</guid><wfw:comment>http://www.aygfsteel.com/Crying/comments/153982.html</wfw:comment><comments>http://www.aygfsteel.com/Crying/articles/153982.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/Crying/comments/commentRss/153982.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/Crying/services/trackbacks/153982.html</trackback:ping><description><![CDATA[<p><tr>  <br />    <th> ID  </th><br />     <th> 姓名</th><br />     <th>密码</th><br />     <th>  删除? </th><br /> </tr><br /> <%<br />     List userList=(List)request.getAttribute("userList");<br />     for(int i=0;i<userList.size();i++)<br />     {<br />       TUser tUser=(TUser)userList.get(i);<br />    %><br />    <tr><br />    <td ><%=tUser.getUsername() %></td><br />    <br />    <td><%=tUser.getPassword() %></td><br />     <td><br />    <html:link action="/deleteUser.do?userId=${User.id}">&nbsp;&nbsp;删除</html:link><br />  </td><br />    </tr><br />    <%<br />    <br />      }<br />     %><br /> /*********************************************************************************/</p> <p><tr><br />        <th><br />      ID<br />     </th><br />     <th><br />      姓名<br />     </th><br />     <th><br />      密码<br />     </th><br />     <th><br />      删除?<br />     </th><br />     <br />                </tr></p> <p>   <logic:present name="userList" scope="request"><br />     <logic:iterate id="User" name="userList" indexId="index"><br />      <tr><br />       <td><br />        ${User.id}<br />       </td><br />       <td><br />        <bean:write name="User" property="username" /><br />       </td><br />       <td><br />        <bean:write name="User" property="password" /><br />       </td><br />       <td><br />        <html:link action="/deleteUser.do?userId=${User.id}">&nbsp;&nbsp;删除</html:link><br />       </td></p> <p>     </tr><br />     </logic:iterate></p> <p>   </logic:present></p> <p>///////////////***********************************//////////////////////////<br /> <body><br />   <%<br />        HashMap<String,String> mapYear=new HashMap<String,String>();<br />        mapYear.put("0","1980");<br />        mapYear.put("1","1981");<br />        mapYear.put("2","1982");<br />        mapYear.put("3","1983");<br />        request.setAttribute("mapYear",mapYear);<br />         HashMap<String,String> mapMonth=new HashMap<String,String>();<br />        mapMonth.put("0","01");<br />        mapMonth.put("1","02");<br />        mapMonth.put("2","03");<br />        mapMonth.put("3","04");<br />        request.setAttribute("mapMonth",mapMonth);<br />         HashMap<String,String> mapDay=new HashMap<String,String>();<br />        mapDay.put("0","1");<br />        mapDay.put("1","2");<br />        mapDay.put("2","3");<br />        mapDay.put("3","4");<br />        request.setAttribute("mapDay",mapDay);<br />   %></p> <p>  <html:form action="/addStudent" focus="username"><br />   <br />      username : <html:text property="username" /><br />    <html:errors property="username" /><br />    <br /><br />      password : <html:password property="password" /><br />    <html:errors property="password" /><br />    <br /><br />    <br />    sex : <html:radio property="sex" value="m" />?<br />           <html:radio property="sex" value="f" />?lt;br /><br />    <br />    birthday :<html:select property="birthdayYear" size="1"><br />     <logic:iterate id="map1" name="mapYear" indexId="id"><br />      <html:option value="${map1.value}">${map1.value}</html:option><br />     </logic:iterate><br />    </html:select>q?br />                 <html:select property="birthdayMonth" size="1"><br />     <logic:iterate id="map2" name="mapMonth" indexId="id"><br />      <html:option value="${map2.value}">${map2.value}</html:option><br />     </logic:iterate><br />    </html:select>?br />             <html:select property="birthdayDay" size="1"><br />     <logic:iterate id="map3" name="mapDay" indexId="id"><br />      <html:option value="${map3.value}">${map3.value}</html:option><br />     </logic:iterate><br />    </html:select>?lt;br /><br />             <br />     <br />    grade : <html:text property="grade" /><br />    <br />    <br /><br />    <html:submit /><br />    <html:cancel /><br />   </html:form><br />  </body><br /> /*********************struts中隔行颜色不同的昄*************************************/<br /> <br /> <br /> <logic:iterate id="Produt" name="list" indexId="id"><br />     <bean:define id="result" value="${Produt.id%2}"></bean:define><br />     <logic:equal value="0" name="result"><br />    <tr bgcolor="<span style="color: #00ff00">green</span>"></p> <p>    <td><br />      ${Produt.typeId}<br />     </td><br />     <td><br />      ${Produt.name}<br />     </td><br />     <td><br />      ${Produt.price}<br />     </td><br />     <td><br />      ${Produt.meno}<br />     </td><br />                  <br />    </tr><br />    </logic:equal><br />     <logic:equal value="1" name="result"><br />    <tr bgcolor="<span style="color: #ffff00">yellow</span>"></p> <p>    <td><br />      ${Produt.typeId}<br />     </td><br />     <td><br />      ${Produt.name}<br />     </td><br />     <td><br />      ${Produt.price}<br />     </td><br />     <td><br />      ${Produt.meno}<br />     </td><br />                  <br />    </tr><br />    </logic:equal><br />   </logic:iterate></p> <img src ="http://www.aygfsteel.com/Crying/aggbug/153982.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/Crying/" target="_blank">Crying</a> 2007-10-18 19:10 <a href="http://www.aygfsteel.com/Crying/articles/153982.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JSP/Servlet中的重定向技术的lDhttp://www.aygfsteel.com/Crying/articles/153670.htmlCryingCryingWed, 17 Oct 2007 12:05:00 GMThttp://www.aygfsteel.com/Crying/articles/153670.htmlhttp://www.aygfsteel.com/Crying/comments/153670.htmlhttp://www.aygfsteel.com/Crying/articles/153670.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/153670.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/153670.html有段旉没看JSP?jin),q不发C(jin)一个好东西我就”无?#8220;的{来了(jin)Q以便自己学?/span>
1.RequestDispatcher.forward()

是在服务器端起作?当用forward()?Servlet engine传递HTTPh从当前的Servlet or JSP到另外一个Servlet,JSP 或普通HTML文g,也即你的form提交至a.jsp,在a.jsp用到?jin)forward()重定向至b.jsp,此时form提交的所有信息在b.jsp都可以获?参数自动传?

但forward()无法重定向至有frame的jsp文g,可以重定向至有frame的html文g,同时forward()无法在后面带参数传?比如servlet?name=frank,q样不行,可以E序内通过response.setAttribute("name",name)来传至下一个页?

重定向后览器地址栏URL不变.

?在servlet中进行重定向


public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{

response.setContentType("text/html; charset=gb2312");

ServletContext sc = getServletContext();

RequestDispatcher rd = null;

rd = sc.getRequestDispatcher("/index.jsp"); //定向的页?br />
rd.forward(request, response);

}


通常在servlet中用,不在jsp中用?

2.response.sendRedirect()

是在用户的浏览器端工?sendRedirect()可以带参C?比如servlet?name=frank传至下个面,同时它可以重定向至不同的L?sendRedirect()可以重定向有frame.的jsp文g.

重定向后在浏览器地址栏上?x)出现重定向面的URL

?在servlet中重定向


public void doPost(HttpServletRequest request,HttpServletResponse response)

throws ServletException,IOException

{

response.setContentType("text/html; charset=gb2312");

response.sendRedirect("/index.jsp");

}


׃response是jsp面中的隐含对象Q故在jsp面中可以用response.sendRedirect()直接实现重定位?

注意Q?

(1).使用response.sendRedirectӞ前面不能有HTML输出?

qƈ不是l对的,不能有HTML输出其实是指不能有HTML被送到?jin)浏览器。事实上现在的server都有cache机制Q一般在8KQ我是说JSP SERVERQ,q就意味着Q除非你关闭?jin)cacheQ或者你使用?jin)out.flush()强制hQ那么在使用sendRedirect之前Q有量的HTML输出也是允许的?

(2).response.sendRedirect之后Q应该紧跟一句return;

我们已经知道response.sendRedirect是通过览器来做{向的Q所以只有在面处理完成后,才会(x)有实际的动作。既然你已经要做转向?jin),那么后的输出q有什么意义呢Q而且有可能会(x)因ؓ(f)后面的输出导致{向失败?

比较Q?

(1).RequestDispatcher.forward()是容器中控制权的转向Q在客户端浏览器地址栏中不会(x)昄?gu){向后的地址Q?

(2).response.sendRedirect()则是完全的蟩转,览器将?x)得到蟩转的地址Qƈ重新发送请求链接。这P从浏览器的地址栏中可以看到跌{后的链接地址?

前者更加高效,在前者可以满需要时Q尽量用RequestDispatcher.forward()Ҏ(gu).

注:(x)在有些情况下Q比如,需要蟩转到一个其它服务器上的资源Q则必须使用HttpServletResponse.sendRedirect()Ҏ(gu)?

3.


<jsp:forward page="" />


它的底层部分是由RequestDispatcher来实现的Q因此它带有RequestDispatcher.forward()Ҏ(gu)的印记?

如果?jsp:forward 之前有很多输?前面的输出已使缓冲区?自动输出到客户?那么该语句将不v作用,q一点应该特别注意?

另外要注意:(x)它不能改变浏览器地址Q刷新的话会(x)D重复提交

4.修改HTTP header的Location属性来重定?

通过讄直接修改地址栏来实现面的重定向?

jsp文g代码如下Q?


<Q?br /> response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
String newLocn = "/newpath/jsa.jsp";
response.setHeader("Location",newLocn);
Q?gt;


5.JSP中实现在某页面停留若q秒?自动重定向到另一面

在html文g中,下面的代码:(x)


Ҏ(gu)1###<meta http-equiv="refresh" content="300; url=target.jsp">
Ҏ(gu)2###Q我喜欢的)(j)<%response.setHeader("refresh","300;URL=target.jsp") ; %>


它的含义Q在5分钟之后正在览的页面将?x)自动变(sh)target.htmlq一c(din)代码中300为刷新的延迟旉Q以Uؓ(f)单位。targer.htmlZ惌{向的目标?若ؓ(f)本页则ؓ(f)自动h本页?

׃可知Q可以通过setHeader来实现某面停留若干U后,自动重定向到另一面?

关键代码Q?

String content=stayTime+";URL="+URL;

response.setHeader("REFRESH",content);


Crying 2007-10-17 20:05 发表评论
]]>
jsp如何q数据库http://www.aygfsteel.com/Crying/articles/153378.htmlCryingCryingTue, 16 Oct 2007 13:07:00 GMThttp://www.aygfsteel.com/Crying/articles/153378.htmlhttp://www.aygfsteel.com/Crying/comments/153378.htmlhttp://www.aygfsteel.com/Crying/articles/153378.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/153378.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/153378.html 

现在有好多初学jsp的网友经怼(x)问数据库怎么q接啊,怎么老出错啊Q所以我集中的在q写文章供大家参考,其实q种把数据库逻辑全部攑֜jsp里未必是好的做法Q但是有利于初学者学?fn),所以我p样做?jin),当大家学C定程度的时候,可以考虑用MVC的模式开发。在l习(fn)q些代码的时候,你一定将jdbc的驱动程序放到服务器的类路径里,然后要在数据库里Z个表test,有两个字D|如ؓ(f)test1Qtest2Q可以用下面SQL?
  create table test(test1 varchar(20),test2 varchar(20)
然后向这个表写入一条测试纪录,那么现在开始我们的jsp和数据库之旅吧?/p>

  一、jspq接Oracle8/8i/9i数据库(用thin模式Q?
  testoracle.jsp如下Q?
  <%@ page contentType="text/html;charset=gb2312"%>
  <%@ page import="java.sql.*"%>
  <html>
  <body>
  <%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
  String url="jdbc:oracle:thin:@localhost:1521:orcl";
  //orclZ的数据库的SID
  String user="scott";
  String password="tiger";
  Connection conn= DriverManager.getConnection(url,user,password);
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sql="select * from test";
  ResultSet rs=stmt.executeQuery(sql);
  while(rs.next()) {%>
  (zhn)的W一个字D内容ؓ(f)Q?lt;%=rs.getString(1)%>
  (zhn)的W二个字D内容ؓ(f)Q?lt;%=rs.getString(2)%>
  <%}%>
  <%out.print("数据库操作成功,恭喜?);%>
  <%rs.close();
  stmt.close();
  conn.close();
  %>
  </body>
  </html>

二、jspq接Sql Server7.0/2000数据?
  testsqlserver.jsp如下Q?
  <%@ page contentType="text/html;charset=gb2312"%>
  <%@ page import="java.sql.*"%>
  <html>
  <body>
  <%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
  String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
  //pubsZ的数据库?
  String user="sa";
  String password="";
  
  Connection conn= DriverManager.getConnection(url,user,password);
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sql="select * from test";
  ResultSet rs=stmt.executeQuery(sql);
  while(rs.next()) {%>
  (zhn)的W一个字D内容ؓ(f)Q?lt;%=rs.getString(1)%>
  (zhn)的W二个字D内容ؓ(f)Q?lt;%=rs.getString(2)%>
  <%}%>
  <%out.print("数据库操作成功,恭喜?);%>
  <%rs.close();
  stmt.close();
  conn.close();
  
  %>
  </body>
  </html>

三、jspq接DB2数据?
  testdb2.jsp如下Q?
  <%@ page contentType="text/html;charset=gb2312"%>
  <%@ page import="java.sql.*"%>
  <html>
  <body>
  <%Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
  String url="jdbc:db2://localhost:5000/sample";
  //sampleZ的数据库?
  String user="admin";
  String password="";
  Connection conn= DriverManager.getConnection(url,user,password);
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sql="select * from test";
  ResultSet rs=stmt.executeQuery(sql);
  while(rs.next()) {%>
  (zhn)的W一个字D内容ؓ(f)Q?lt;%=rs.getString(1)%>
  (zhn)的W二个字D内容ؓ(f)Q?lt;%=rs.getString(2)%>
  <%}%>
  <%out.print("数据库操作成功,恭喜?);%>
  <%rs.close();
  stmt.close();
  conn.close();
  %>
  </body>
  </html> (代码实验?
四、jspq接Informix数据?
  testinformix.jsp如下Q?
  <%@ page contentType="text/html;charset=gb2312"%>
  <%@ page import="java.sql.*"%>
  <html>
  <body>
  <%Class.forName("com.informix.jdbc.IfxDriver").newInstance();
  String url =
  "jdbc:informix-sqli://123.45.67.89:1533/testDB:INFORMIXSERVER=myserver;
  user=testuser;password=testpassword";
  //testDBZ的数据库?
  Connection conn= DriverManager.getConnection(url);
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sql="select * from test";
  ResultSet rs=stmt.executeQuery(sql);
  while(rs.next()) {%>
  (zhn)的W一个字D内容ؓ(f)Q?lt;%=rs.getString(1)%>
  (zhn)的W二个字D内容ؓ(f)Q?lt;%=rs.getString(2)%>
  <%}%>
  <%out.print("数据库操作成功,恭喜?);%>
  <%rs.close();
  stmt.close();
  conn.close();
  %>
  </body>
  </html>

五、jspq接Sybase数据?
  testmysql.jsp如下Q?
  <%@ page contentType="text/html;charset=gb2312"%>
  <%@ page import="java.sql.*"%>
  <html>
  <body>
  <%Class.forName("com.sybase.jdbc.SybDriver").newInstance();
  String url =" jdbc:sybase:Tds:localhost:5007/tsdata";
  //tsdataZ的数据库?
  Properties sysProps = System.getProperties();
  SysProps.put("user","userid");
  SysProps.put("password","user_password");
  Connection conn= DriverManager.getConnection(url, SysProps);
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sql="select * from test";
  ResultSet rs=stmt.executeQuery(sql);
  while(rs.next()) {%>
  (zhn)的W一个字D内容ؓ(f)Q?lt;%=rs.getString(1)%>
  (zhn)的W二个字D内容ؓ(f)Q?lt;%=rs.getString(2)%>
  <%}%>
  <%out.print("数据库操作成功,恭喜?);%>
  <%rs.close();
  stmt.close();
  conn.close();
  %>
  </body>
  </html>

六、jspq接MySQL数据?
  testmysql.jsp如下Q?
  <%@ page contentType="text/html;charset=gb2312"%>
  <%@ page import="java.sql.*"%>
  <html>
  <body>
  <%Class.forName("org.gjt.mm.mysql.Driver").newInstance();
  String url ="jdbc:mysql://localhost/softforum?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
  //testDBZ的数据库?
  Connection conn= DriverManager.getConnection(url);
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sql="select * from test";
  ResultSet rs=stmt.executeQuery(sql);
  while(rs.next()) {%>
  (zhn)的W一个字D内容ؓ(f)Q?lt;%=rs.getString(1)%>
  (zhn)的W二个字D内容ؓ(f)Q?lt;%=rs.getString(2)%>
  <%}%>
  <%out.print("数据库操作成功,恭喜?);%>
  <%rs.close();
  stmt.close();
  conn.close();
  %>
  </body>
  </html>

七、jspq接PostgreSQL数据?
  testmysql.jsp如下Q?
  <%@ page contentType="text/html;charset=gb2312"%>
  <%@ page import="java.sql.*"%>
  <html>
  <body>
  <%Class.forName("org.postgresql.Driver").newInstance();
  String url ="jdbc:postgresql://localhost/soft"
  //softZ的数据库?
  String user="myuser";
  String password="mypassword";
  Connection conn= DriverManager.getConnection(url,user,password);
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  String sql="select * from test";
  ResultSet rs=stmt.executeQuery(sql);
  while(rs.next()) {%>
  (zhn)的W一个字D内容ؓ(f)Q?lt;%=rs.getString(1)%>
  (zhn)的W二个字D内容ؓ(f)Q?lt;%=rs.getString(2)%>
  <%}%>
  <%out.print("数据库操作成功,恭喜?);%>
  <%rs.close();
  stmt.close();
  conn.close();
  %>
  </body>
  </html>  



Crying 2007-10-16 21:07 发表评论
]]>
利用servlet监听器实现jsp中在Uh数统计的Ҏ(gu) http://www.aygfsteel.com/Crying/articles/151660.htmlCryingCryingWed, 10 Oct 2007 03:10:00 GMThttp://www.aygfsteel.com/Crying/articles/151660.htmlhttp://www.aygfsteel.com/Crying/comments/151660.htmlhttp://www.aygfsteel.com/Crying/articles/151660.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/151660.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/151660.html

111
ServletListenerJ2EEHttpSessionJ2EEHttpSessionHttpSessionHttpSessionListenerHttpSessionListenersessionCreatedJ2EEHttpSessionHttpSessionHttpSessionListenersessionDestroyed
sessionCreatedsessionDestroyedHttpSessionListenersessionCreated1sessionDestroyed1
HttpSessionListenerJ2EE
  首先Q编写一个简单的计数器,代码如下Q?/span>

1.    package accp.onlinecounter;

2.    public class OnlineCounter {

3.        private static long online = 0;    

4.        public static long getOnline() {

5.            return online;

6.        }    

7.        public static void raise(){

8.            online++;

9.        } 

10.       public static void reduce(){

11.           online--;

12.      }

13.   }


HttpSessionListenersessionCreatedOnlineCounterraisesessionDestroyedOnlineCounterreduceҎ(gu)Q代码如下:(x)

1.    package accp.onlinecounter;

2.    import javax.servlet.http.HttpSessionEvent;

3.    import javax.servlet.http.HttpSessionListener;

4.    public class OnlineCounterListener implements HttpSessionListener {

5.        public void sessionCreated(HttpSessionEvent hse) {

6.            OnlineCounter.raise();

7.        }

8.        public void sessionDestroyed(HttpSessionEvent hse) {

9.            OnlineCounter.reduce();

10.       }

11.   }


HttpSessionListenerweb.xml中加入如下内容:(x)

1.    <web-app>

2.        ……

3.        <listener>

4.            <listener-class>

5.                accp.OnlineCounterListener

6.            </listener-class>

7.        </listener>

8.        ……

9.    </web-app>


OKJSP面中加入下面这L(fng)脚本p昄但前在线人数?jin)?x)

1.    <%@ page language="java" pageEncoding="GB2312" %>

2.    <%@ page import="accp.OnlineCounter" %>

3.    <html>

4.        <head><title>On Line Counert</title></head>

5.        <body bgcolor="#FFFFFF">

6.            On line:<%=OnlineCounter.getOnline()%>
7.        </body>

8.    </html>



Crying 2007-10-10 11:10 发表评论
]]>
用java实现Ҏ(gu)件的各种操作http://www.aygfsteel.com/Crying/articles/148971.htmlCryingCryingFri, 28 Sep 2007 02:09:00 GMThttp://www.aygfsteel.com/Crying/articles/148971.htmlhttp://www.aygfsteel.com/Crying/comments/148971.htmlhttp://www.aygfsteel.com/Crying/articles/148971.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/148971.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/148971.html 

 文g的徏?(g)查与删除

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>文g的徏立、检查与删除</title>
</head>
<body>
<%
String path=request.getRealPath("");
//out.println(path);
File f=new File(path,"File.txt");
//out.println(f);
//out.println(f.exists());

if(f.exists()){//(g)查File.txt是否存在
f.delete();//删除File.txt文g
out.println(path + "\\File.txt 存在Q已删除?);
}else{
f.createNewFile();//在当前目录下建立一个名为File.txt的文?
out.println(path + "\\File.txt 不存在,已徏立?);//输出目前所在的目录路径
}
%>

  目录的徏?(g)查与删除

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>目录的徏?(g)查与删除</title>
</head>
<body>
<%
String path=request.getRealPath("");
path=path + "\\Sub";//要建立的目录\?
File d=new File(path);//建立代表Sub目录的File对象Qƈ得到它的一个引?
if(d.exists()){//(g)查Sub目录是否存在
d.delete();
out.println("Sub目录存在Q已删除");
}else{
d.mkdir();//建立Sub目录
out.println("Sub目录不存在,已徏?);
}
%>
</body>
</html>

  如何在JSP中处理虚拟目?

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>JSP中如何处理虚拟目?lt;/title>
</head>
<body>
取得虚拟目录对应的磁盘\?lt;br>
Web站点ȝ录的位置?lt;font color=#ff0000><%=request.getRealPath("/")%></font><br>
JSP|页所在的目录位置<font color=#ff0000><%=request.getRealPath("./")%></font><br>
JSP|页所在目录上一层目录的位置<font color=#ff0000><%=request.getRealPath("../")%></font><br>
</body>
</html>

文g属性的取得

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.util.Date,java.io.*"%>
<html>
<head>
<title>文g属性的取得</title>
</head>
<body>
<%
String path=request.getRealPath("/");
File f=new File(path,"ReadData.txt");
if(f.exists()){
%>
<%=f.getName()%>的属性如下:(x)<br><br>
文g长度为:(x)<%=f.length()%>
<%=f.isFile()?"是文?:"不是文g"%><br>
<%=f.isDirectory()?"是目?:"不是目录"%><br>
<%=f.canRead()?"可读?:"不可d"%><br>
<%=f.canWrite()?"可写?:"不可写入"%><br>
<%=f.isHidden()?"是隐藏文?:"不是隐藏文g"%><br>
文g的最后修Ҏ(gu)期ؓ(f)Q?lt;%=new Date(f.lastModified())%><br>
<%
}else{
f.createNewFile();//在当前目录下建立一个名为ReaData.txt的文?
%>
<%=f.getName()%>的属性如下:(x)<br><br>
文g长度为:(x)<%=f.length()%>
<%=f.isFile()?"是文?:"不是文g"%><br>
<%=f.isDirectory()?"是目?:"不是目录"%><br>
<%=f.canRead()?"可读?:"不可d"%><br>
<%=f.canWrite()?"可写?:"不可写入"%><br>
<%=f.isHidden()?"是隐藏文?:"不是隐藏文g"%><br>
文g的最后修Ҏ(gu)期ؓ(f)Q?lt;%=new Date(f.lastModified())%><br>
<%
}
%>
</body>
</html>

  取出目录中文件的Ҏ(gu)

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>取出目录中文件的Ҏ(gu)--列出目录中的文g</title>
</head>
<body>
<%
String path=request.getRealPath("/");
File d=new File(path);//建立当前目录中文件的File对象
File list[]=d.listFiles();//取得代表目录中所有文件的File对象数组
out.println("<font color=#ff0000>" + path + "目录下的文gQ?lt;/font><br>");
for(int i=0;i<list.length;i++){
if(list<I>.isFile()){
out.println(list<I>.getName() + "<br>");
}
}
out.println("<br><font color=#ff0000>" + path + "目录下的目录Q?lt;/font><br>");
for(int i=0;i<list.length;i++){
if(list<I>.isDirectory()){
out.println(list<I>.getName() + "<br>");
}
}
%>
</body>
</html>

 判断是否为空白文?

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>判断是否为空白文?lt;/title>
</head>
<body>
<%
String path=request.getRealPath("/");
out.println(path);
FileReader fr=new FileReader(path + "\\AtEnd.txt");//建立FileReader对象Qƈ实例化ؓ(f)fr
//对FileReadercȝ成的对象使用read()Ҏ(gu)Q可以从字符中d下一个字W?
if(fr.read()==-1)//判断是否已读到文件的l尾
{
out.print("AtEnd.txt文g中没有数?lt;br>");
}else{
out.println("AtEnd.txt文g中有数据");
}
fr.close();
%>
</body>
</html>
    <B>d所有的文g数据</B>
<ccid_nobr>
<table width="400" border="1" cellspacing="0" cellpadding="2"
bordercolorlight = "black" bordercolordark = "#FFFFFF" align="center">
<tr>
<td bgcolor="e6e6e6" class="code" style="font-size:9pt">
<pre><ccid_code> <%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*,java.lang.*"%>
<html>
<head>
<title>d所有的文g数据</title>
</head>
<body>
<%
String path=request.getRealPath(".");
FileReader fr=new FileReader(path + "\\ReadData.txt");
//关键在于dq程中,要判断所d的字W是否已l到?jin)文件的末尾Q?
q且q个字符是不是文件中的断行符Q即判断该字W值是否ؓ(f)13?
int c=fr.read();//从文件中d一个字W?
//判断是否已读到文件结?
while(c!=-1){
out.print((char)c);//输出d的数?
c=fr.read();//从文件中l箋(hu)d数据
if(c==13){//判断是否为断行字W?
out.print("<br>");//输出分行标签
fr.skip(1);//略过一个字W?
//c=fr.read();//d一个字W?
}
}
fr.close();
%>
</body>
</html>

  一行一行读取数?

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>文gd</title>
</head>
<body>
<%
String path=request.getRealPath("");//取得当前目录的\?
FileReader fr=new FileReader(path + "\\file\\inc\\t.txt");//建立FileReader对象Qƈ实例化ؓ(f)fr
BufferedReader br=new BufferedReader(fr);//建立BufferedReader对象Qƈ实例化ؓ(f)br
String Line=br.readLine();//从文件读取一行字W串
//判断d到的字符串是否不为空
while(Line!=null){
out.println(Line + "<br>");//输出从文件中d的数?
Line=br.readLine();//从文件中l箋(hu)d一行数?
}
br.close();//关闭BufferedReader对象
fr.close();//关闭文g
%>
</body>
</html>


略过文g中的字符不读?

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>略过字节不读?lt;/title>
</head>
<body>
<%
String path=request.getRealPath(".");
FileReader fr=new FileReader(path + "\\ReadData.txt");
fr.skip(2);//跌2个字?
int c=fr.read();//d一个字?
while(c!=-1){
out.print((char)c);
c=fr.read();
}
fr.close();
%>
</body>
</html>

  数据写入文?

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>数据写入文?lt;/title>
</head>
<body>
<%
String path=request.getRealPath(".");
FileWriter fw=new FileWriter(path + "\\WriteData.txt");//建立FileWriter对象Qƈ实例化fw
//字W串写入文g
fw.write("大家好!");
fw.write("本书是《JSP~程技巧?);
fw.write("请多多指教!");
fw.write("email:stride@sina.com");
fw.close();

FileReader fr=new FileReader(path + "\\WriteData.txt");
BufferedReader br=new BufferedReader(fr);//建立BufferedReader对象Qƈ实例化ؓ(f)br
String Line=br.readLine();
//d一行数?
out.println(Line + "<br>");
br.close();//关闭BufferedReader对象
fr.close();
%>
</body>
</html>

  写入文件的数据分行

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>写入文件的数据分行</title>
</head>
<body>
<%
String path=request.getRealPath(".");
FileWriter fw=new FileWriter(path + "\\WriteData.txt");
BufferedWriter bw=new BufferedWriter(fw);
bw.write("大家好!");
bw.write("本书是《JSP~程技巧》?);
bw.newLine();//断行
bw.write("请多多指教!");
bw.newLine();//断行
bw.write("email: stride@sina.com");
bw.flush();//数据更新至文g
fw.close();//关闭文g?
out.println("写入文g内容为:(x)<br>");
FileReader fr=new FileReader(path + "\\WriteData.txt");
BufferedReader br=new BufferedReader(fr);
String Line=br.readLine();//d一行数?
while(Line!=null){
out.println(Line + "<br>");
Line=br.readLine();
}
fr.close();
%>
</body>
</html>

  如何数据追加写入到文g

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>写入文件的数据分行</title>
</head>
<body>
<%
String path=request.getRealPath(".");
RandomAccessFile rf=new RandomAccessFile(path + "\\WriteData.txt","rw");
//定义一个类RandomAccessFile的对象,q实例化
rf.seek(rf.length());//指针移动到文g末尾
rf.writeBytes("\nAppend a line to the file!");
rf.close();//关闭文g?
out.println("写入文g内容为:(x)<br>");
FileReader fr=new FileReader(path + "\\WriteData.txt");
BufferedReader br=new BufferedReader(fr);//d文g的BufferedRead对象
String Line=br.readLine();
while(Line!=null){
out.println(Line + "<br>");
Line=br.readLine();
}
fr.close();//关闭文g
%>
</body>
</html></I></I></I></I>



Crying 2007-09-28 10:09 发表评论
]]>
获得jsp路径http://www.aygfsteel.com/Crying/articles/148956.htmlCryingCryingFri, 28 Sep 2007 01:35:00 GMThttp://www.aygfsteel.com/Crying/articles/148956.htmlhttp://www.aygfsteel.com/Crying/comments/148956.htmlhttp://www.aygfsteel.com/Crying/articles/148956.html#Feedback0http://www.aygfsteel.com/Crying/comments/commentRss/148956.htmlhttp://www.aygfsteel.com/Crying/services/trackbacks/148956.html如果你请求的URL?nbsp; http://localhost:8080/demo/Index.jsp

request.getScheme()    ~~~~~~>          http
request.getServerName()   ~~~~~~>  localhost
request.getServerPort() ~~~~~~~~~>  8080

request.getContextPath()    ~~~~~~>   /demo
request.getRequestPath()
  ~~~~~~~>  /Index.jsp
request.gerRequestURI()  ~~~~~~~>    /demo/Index.jsp

request.getRequestURL()
  ~~~~~~~>  http://localhost:8080/demo/Index.jsp

request.getRealPath("") ~~~~~~~~~> D:\apache-tomcat-6.0.10\webapps\demo



别h写的http://blog.csdn.net/luobo525/archive/2006/11/21/1401577.aspx




Crying 2007-09-28 09:35 发表评论
]]>
struts中的文g上传和下?/title><link>http://www.aygfsteel.com/Crying/articles/146747.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Thu, 20 Sep 2007 04:06:00 GMT</pubDate><guid>http://www.aygfsteel.com/Crying/articles/146747.html</guid><wfw:comment>http://www.aygfsteel.com/Crying/comments/146747.html</wfw:comment><comments>http://www.aygfsteel.com/Crying/articles/146747.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.aygfsteel.com/Crying/comments/commentRss/146747.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/Crying/services/trackbacks/146747.html</trackback:ping><description><![CDATA[JSP面<br />  <%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><br /> <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> <br /> <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%> <br /> <html> <br />  <head><br />   <title>JSP for FileForm form</title><br />  </head><br />  <body><br />   <html:form action="/file"<span style="color: #0000ff"> enctype="multipart/form-data"</span>><br />    上传 :<span style="color: #0000ff"> <html:file property="myFile"/></span><html:errors name="fileError"/><br />    <html:submit value="上传"/><br />   </html:form><br />   <html:img src="image/dd.jpg"/><br />  </body><br /> </html><br /> <br /> /*******************************************************************************/<br /> 对应的ActionForm<br /> package wsq.struts.form; <p>import javax.servlet.http.HttpServletRequest;<br /> import org.apache.struts.action.ActionErrors;<br /> import org.apache.struts.action.ActionForm;<br /> import org.apache.struts.action.ActionMapping;<br /> import org.apache.struts.upload.FormFile;</p> <p>/** <br />  * MyEclipse Struts<br />  * Creation date: 09-17-2007<br />  * <br />  *   @author 王世?br />  **/<br /> public class FileForm extends ActionForm {<br />  <br />  private static final long serialVersionUID = 1L;</p> <p> private FormFile myFile;</p> <p> public ActionErrors validate(ActionMapping mapping,<br />    HttpServletRequest request) {<br />   return null;<br />  }</p> <p> public void reset(ActionMapping mapping, HttpServletRequest request) {<br />   <br />  }</p> <p> <br />  public static long getSerialVersionUID() {<br />   return serialVersionUID;<br />  }</p> <p> public FormFile getMyFile() {<br />   return myFile;<br />  }</p> <p> public void setMyFile(FormFile myFile) {<br />   this.myFile = myFile;<br />  }</p> <p> </p> <p> <br /> }</p> <br />   <br /> <br /> /**********************************************************/<br /> 对应的Action <br /> <br /> <p><br /> package wsq.struts.action;<br /> import java.io.FileOutputStream;<br /> import java.io.IOException;<br /> import java.io.InputStream;<br /> import java.io.OutputStream;<br /> import javax.servlet.http.HttpServletRequest;<br /> import javax.servlet.http.HttpServletResponse;<br /> import org.apache.struts.action.Action;<br /> import org.apache.struts.action.ActionForm;<br /> import org.apache.struts.action.ActionForward;<br /> import org.apache.struts.action.ActionMapping;<br /> import org.apache.struts.upload.FormFile;</p> <p>import wsq.struts.form.FileForm;</p> <p>public class FileAction extends Action {<br />     </p> <p> public ActionForward execute(ActionMapping mapping, ActionForm form,<br />    HttpServletRequest request, HttpServletResponse response)  throws IOException{<br />   FileForm fileForm = (FileForm) form;<br />   <br />   FormFile file = fileForm.getMyFile();<br />   if (file == null)<br />   {   <br />    return mapping.findForward("error");<br />   }<br />  String dir=servlet.getServletContext().getRealPath("/image");//首先在你的项目下新徏个(?nbsp;webroot下)(j)image文g?br /> /***注释的是按孙卫琴书上来的*************/<br /> //  InputStream in=file.getInputStream();<br /> //  OutputStream out=new FileOutputStream(dir+"/"+file.getFileName());<br /> //  int bytesRead=0;<br /> //  byte [] buffer=new byte[8000];<br /> //  while((bytesRead=in.read(buffer, 0, 8000))!=-1)<br /> //  {<br /> //   out.write(buffer,0,bytesRead);<br /> //   <br /> //  }<br />    <br />   FileOutputStream out = new FileOutputStream(dir+"/" + file.getFileName()); <br />   out.write(file.getFileData()); </p> <p>  out.close(); <br />   //in.close();<br />   file.destroy();<br />  <br />   System.out.println(file.getFileName()+"上传文g的名?);<br />   return null;<br />  }<br /> }<br /> </p> <br /> <br /> <br /> /*************************************/<br /> 大家q要记得传图片是?x)出现文件名q 解决的办法是写个qo(h)?<br />   要是不想写可以在<br />                ?的TOMCATE目录下的\webapps\examples\WEB-INF\classes\filters\SetCharacterEncodingFilter.java<br /> TOMCAT也ؓ(f)你写好一个现成的  拿来可以用?br /> q两天尝?用AJAX来写一个文件上传的  呵呵。。?br /> <br /> <br /> <br /> <br /> <img src ="http://www.aygfsteel.com/Crying/aggbug/146747.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/Crying/" target="_blank">Crying</a> 2007-09-20 12:06 <a href="http://www.aygfsteel.com/Crying/articles/146747.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>struts 更深的理?/title><link>http://www.aygfsteel.com/Crying/articles/145872.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Mon, 17 Sep 2007 07:36:00 GMT</pubDate><guid>http://www.aygfsteel.com/Crying/articles/145872.html</guid><wfw:comment>http://www.aygfsteel.com/Crying/comments/145872.html</wfw:comment><comments>http://www.aygfsteel.com/Crying/articles/145872.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/Crying/comments/commentRss/145872.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/Crying/services/trackbacks/145872.html</trackback:ping><description><![CDATA[<strong>J2EE?/strong><br /> <br />   J2EE是一个开攄、基于标准的q_Q可以开发、部|和理N层结构的、面向Web的、以服务器ؓ(f)中心(j)的企业应用Q它是利用Java 2 q_来简化与多企业解决Ҏ(gu)的开发、部|和理相关的诸多复杂问题的应用体系l构?br /> <br />   J2EEq_采用一个多层次分布式的应用模式。这意味着应用逻辑Ҏ(gu)功能被划分成lgQ组成J2EE应用的不同应用组件安装在不同的服务器上,q种划分是根据应用组件属于多层次J2EE环境中的哪一个层ơ来军_的。如?所C,J2EE应用可以׃或四个层ơ组成,J2EE多层ơ应用一般被认ؓ(f)是三层应用,因ؓ(f)它们是被分布在三个不同的地点Q客L(fng)机器、J2EE服务器和数据库或后端的传l系l服务器。三层架构应用是Ҏ(gu)准的客户?服务器应用架构的一U扩展, 卛_客户端应用和后台存储之间增加一个多U程应用服务器?<br /> <br /> <table width="90%" align="center" border="0"> <tbody> <tr> <td> <div align="center"><img src="http://java.chinaitlab.com/UploadFiles_8734/200512/20051229095543679.gif" border="0" alt="" /></div> </td> </tr> </tbody> </table> <br />   J2EE体系包括JSP、Servlet、EJB、WEB SERVICE{多Ҏ(gu)术。这些技术的出现l电(sh)子商务时代的WEB应用开发提供了(jin)一个非常有竞争力的选择。怎样把这些技术组合v来,形成一个适应目需要的E_架构是项目开发过E中一个非帔R要的步骤?br /> <br />   一个成功的软g需要有一个成功的架构Q但软g架构的徏立是一个复杂而又持箋(hu)改进的过E,软g开发者们不可能对每个不同的项目做不同的架构,而L量重用以前的架构,或开发出量通用的架构方案,Struts是行的基于J2EE的架构方案之一Q其他常用的ZJ2EE的架构方案还有Turbine、RealMothods{。本文主要探讨Struts框架技术的应用?br /> <br />   <strong>J2EE应用E序架构的发?/strong><br /> <br />   在J2EE应用E序架构的发展\E中Q主要经历了(jin)两个大的阶段Q?br /> <br />   1、Model 1<br /> <br />   在JSP面中结合业务逻辑、服务器端处理程序和HTMLQ在JSP面中同时实现显C、业务逻辑和流E控Ӟ从而快速的完成Web应用开发。这U模型的不之处Q?Q不利于应用扩展和更新?Q业务逻辑和表C逻辑混合在JSP面中没有进行抽象和分离Q不利于应用pȝ业务的重用和改动?br /> <br />   2、Model 2<br /> <br />   表示的是ZMVC模式的框架。根据Model 2Qservlet 处理数据存取和导航流Q?JSP处理表现。Model 2 使Java 工程师和HTML设计者分别工作于它们所擅长和负责的部分。Model 2应用的一部分发生改变q不强求其他部分也跟着发生改变。HTML 开发h员可以改变程序的外观和感觉,q不需要改变后端servlet的工作方式。把应用逻辑、处理过E和昄逻辑分成不同的组件实现。I补了(jin)Model1的不?br /> <br />   Struts框架技?br /> <br />   Struts 框架是ZModel 2 的架构,也就是基于MVC模式的框架技术。它是一个免费的开源的WEB层的应用框架,h很高的可配置性,和有一个不断增长的Ҏ(gu)列表。一个前端控制组Ӟ一pd动作c,动作映射Q处理XML的实用工L(fng)Q服务器端java bean 的自动填充,支持验证的WEB 表单Q国际化支持Q生成HTMLQ实现表现逻辑和模板组成了(jin)struts的灵。图2昄?jin)Strutslg是如何一起工作的?br /> <br /> <table width="90%" align="center" border="0"> <tbody> <tr> <td> <div align="center"><img src="http://java.chinaitlab.com/UploadFiles_8734/200512/20051229095544510.gif" border="0" alt="" /></div> </td> </tr> </tbody> </table> <br />   Struts 的ActionServlet 控制D。其他Struts c,比如Action, 用来讉K业务逻辑cR当 ActionServlet 从容器接收到一个请求,它用URI (或者\?#8220;path”) 来决定哪个Action 用来处理请求。一?Action可以校验输入Qƈ且访问业务层以从数据库或其他数据服务中检索信息?br /> <br />   为校验输入或者用输入来更新数据库, Action 需要知道什么被提交上来。ƈ不是强制每个Action 从请求中抓取q些|而是?ActionServlet 输入绑定到JavaBean中。输?bean是Struts ActionForm ccȝ子类。ActionServlet 通过查找h的\径可以决定用哪个ActionFormQAction 也是通过同样的方法选取的。每个Action都必MHTTP 响应q行应答?通常, Struts Action q不自行加工响应信息Q而是请求{发到其他资源Q比如JSP 面。Struts 提供一个ActionForward c,用来一个页面的路径存储为逻辑名称。当完成业务逻辑后,Action 选择q向Servletq回一个ActionForward。Servlet 然后使用存储在ActionForward 对象中的路径来调用页面完成响应?br /> Struts 这些细节都l定在一个ActionMapping 对象中。每个ActionMapping 相对于一个特定的路径。当某个路径被请求时QServlet 查询ActionMapping 对象。ActionMapping对象告诉servlet哪个Actions?ActionForms ?ActionForwards 被使用?br /> <br />   所有这些细节,关于ActionQ?ActionFormQ?ActionForwardQ?ActionMappingQ以?qing)其他一些东西,都在struts-config.xml 文g中定义?ActionServlet 在启动时dq个配置文gQƈ创徏一个配|对象数据库。在q行ӞStruts 应用Ҏ(gu)的是文g创徏的配|对象,而不是文件本w?br /> <br />   <strong>ZStruts框架的应用设计实?/strong><br /> <br />   本文?#8220;面向铔R行业的|络化制造ASPq_开?#8221;目中的软gU用模块ZQ来说明如何设计ZStruts框架的Web应用。在该模块中Q用户合法登陆网站后Q可以根据需要选择所要租用的软gcd?qing)Y件中的功能模块,认信息提交服务器后Q用户将收到pȝl予的登陆密码,用户卛_登陆|站Q在U用租用YӞ实行业务托管?br /> <br />   Ҏ(gu)目需求分?定该系l必d备的性能?1)良好的交互?工作内容中有相当大的部分是hZ?q就要求pȝ的交互性要强?)较好的可扩展?工作的内容和形式h多变?要求pȝh良好的可扩展性?)良好的可l护?pȝ投入使用?主要是由理员承担系l维护的工作,l护人员?sh)定期变?q就要求pȝ的可l护性强?)h较好的跨q_?用户可能使用各种不同的操作系l?而且Z(jin)适应今后可能的变?pȝ应具有较好的跨^台性。基于以上四?在开发Y件租用模块时,采用J2EE~程环境,q相应采用了(jin)专ؓ(f)J2EE定制的Struts框架?br /> <br />   做基于Struts框架的项目开?关键是要有一个好的整体模?计划好系l中包括哪几个模?每个模块各需要什么样的FormBean、JavaBean,各种处理l果都通过哪些JSP面来展?同时配置好struts-config.xml文g。本pȝ的设计模型如?所C?br /> <br /> <table width="90%" align="center" border="0"> <tbody> <tr> <td> <div align="center"><img src="http://java.chinaitlab.com/UploadFiles_8734/200512/20051229095544817.gif" border="0" alt="" /></div> </td> </tr> </tbody> </table> <br />   ActionServlet接受所有的HTTPh,然后Ҏ(gu)配置文g的内?军_请求映到哪一个Action对象,本系l中有两个Action对象,分别对应着登陆q程软g(LogonAction)和系l反馈密?MailAction)?br /> <br />   LogonAction首先?x)验证用h否已l登?如果没有d则重定向到登录页?Logon.jsp),验证通过后根据请求参数决定下一步的处理,如果用户q没有选择U用软gQ则转到软g介绍U用界面QQuery.jspQ,选择需要租用的软g或Y件的某些模块Q提交信息后QMailAction使服务器向用h交密码,用户接收到密码后Q登陆运行Y件?br /> <br />   如果用户登陆软g成功Q则通过配置文gstruts-config.xml中的ActionForwardQ通过GetInfo对象把该用户U用的Y件信息读取道FormBean中,然后调用JSP面昄Bean里的数据。如果是保存数据信息,则调SaveInfo对象FormBean里保持的信息存入数据库;如果是修改信?则调ModifyInfo对象FormBean里保持的修改后的信息存入数据库;如果是删除数据信?则调用DeleteInfo对象FormBean里保持的信息从数据库中删除?br /> <br />   l过q样设计的系l?用户界面和数据处理已l完全分?再加上在JSP面中用了(jin)自定义标?佉K面中没有?jin)Java的脚本代?q样Web界面的设计和后端E序的编写就有了(jin)清晰的界U?便于开发团队的分工,q且l护h也很方便?br /> <img src ="http://www.aygfsteel.com/Crying/aggbug/145872.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/Crying/" target="_blank">Crying</a> 2007-09-17 15:36 <a href="http://www.aygfsteel.com/Crying/articles/145872.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Struts?/title><link>http://www.aygfsteel.com/Crying/articles/141924.html</link><dc:creator>Crying</dc:creator><author>Crying</author><pubDate>Sat, 01 Sep 2007 06:37:00 GMT</pubDate><guid>http://www.aygfsteel.com/Crying/articles/141924.html</guid><wfw:comment>http://www.aygfsteel.com/Crying/comments/141924.html</wfw:comment><comments>http://www.aygfsteel.com/Crying/articles/141924.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/Crying/comments/commentRss/141924.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/Crying/services/trackbacks/141924.html</trackback:ping><description><![CDATA[<div><font size="3"><strong>一?什么是Struts</strong> </div> <div>框架QF(tun)rameworkQ是可重用的Q半完成的应用程序,可以用来产生专门的定制程序?</div> <div>(zhn)只要细?j)地研究真实的应用程序,׃?x)发现E序大致上由两类性质不同的组件组成,一cME序要处理的具体事务密切相关Q我们不妨把它们叫做业务lgQ另一cL应用服务。比如说Q一个税务征系l和一个图书管理系l会(x)在处理它们的业务斚w存在很大的差异,q些直接处理业务的组件由于业务性质的不同不大可能在不同的系l中重用Q而另一些组件如军_E序向的控制、输入的校验、错误处理及(qing)标签库等q些只与E序相关的组件在不同的系l中可以很好地得到重用。h们自然会(x)惌是把q些在不同应用程序中有共性的一些东西抽取出来,做成一个半成品E序Q这L(fng)半成品就是所谓的E序框架Q再做一个新的东西时׃必白手vӞ而是可以在这个基上开始搭建。实际上Q有些大型Y件企业选择自己搭徏q样的框架。但大多C型软g企业或者其他组l,没有条g自己建立框架?</div> <div>Struts作ؓ(f)一个开攑֎代码的应用框Ӟ在最q几q得C(jin)飞速的发展Q在JSP Web应用开发中应用得非常广泛,有的文献上说它已l成为JSP Web应用框架的事实上的标准。那么,I竟什么是Struts呢? </div> <div>要回{这个问题还得从JSP Web应用的两U基本的l构模式:Model 1和Model 2说vQؓ(f)?jin)给读者一些实实在在的帮助Qƈ力图让学?fn)曲U变得^坦一些,我想采用实例驱动的方法来逐步深入地回{有关问题,因ؓ(f)Q学一门技术的最好方法莫q于在实践中学习(fn)、在实践中体?x),逐步加深对其_实质的理解和把握Q而不是一上来引入一大堆新概念让大家觉得无所适从Q或者死记硬背一大堆概念而面对一个真正的实际需求束手无{。正如,一个h即在书本上学成?jin)游泛_士,只要他不下水Q我想他也是不大可能真正?x)游泳的?</div> <div>Model 1l构如图1所C:(x) </div> <div><img src="http://tech.ccidnet.com/col/attachment/2004/8/320186.jpg" border="0" alt="" /> </div> <div>? </div> <div>mode1 1是一个以JSP文gZ?j)的模式Q在q种模式中JSP面不仅负责表现逻辑Q也负责控制逻辑。专业书c上UC为逻辑耦合在页面中Q这U处理方式,对一些规模很的目如:(x)一个简单的留言,也没什么太大的坏处Q实际上Qh们开始接触一些对自己来说是新的东西的时候,比如Q用JSP讉K数据库时Q往(xin)往(xin)喜欢别h能提供一个包含这一切的单个JSP面Q因样在一个页面上他就可以把握全局Q便于理解。但是,用Model 1模式开发大型时Q程序流向由一些互相能够感知的面军_Q当面很多时要清楚地把握其向是很复杂的事情Q当(zhn)修改一|可能?x)?jing)响相关的很多面Q大有牵一发而动全n的感觉,使得E序的修改与l护变得异常困难Q还有一个问题就是程序逻辑开发与面设计U缠在一P既不便于分工合作也不利于代码的重用,q样的程序其健壮性和可׾~性都不好?</div> <div>Grady Booch{h在UML用户指南一书中Q强调徏模的重要性时Q打?jin)一个制作狗H、私Z宅、和大厦的Ş象比L说明Z处理不同规模的事物时应该采用的合理方法一PZ对不同规模的应用E序也应该采用不同的模式?</div> <div>Z(jin)克服Model 1的缺PZ引入?jin)Model 2Q如?所C:(x) </div> <div><img src="http://tech.ccidnet.com/col/attachment/2004/8/320188.jpg" border="0" alt="" /> </div> <div>? </div> <div>它引入了(jin)"控制?q个概念Q控制器一般由servlet来担任,客户端的h不再直接送给一个处理业务逻辑的JSP面Q而是送给q个控制器,再由控制器根据具体的h调用不同的事务逻辑Qƈ处理结果返回到合适的面。因此,q个servlet控制器ؓ(f)应用E序提供?jin)一个进行前-后端处理的中枢。一斚w入数据的验证、n份认证、日志及(qing)实现国际化编E提供了(jin)一个合适的切入点;另一斚w也提供了(jin)业务逻辑从JSP文g剥离的可能。业务逻辑从JSP面分离后,JSP文g蜕变成一个单U完成显CZQ务的东西Q这是常说的View。而独立出来的事务逻辑变成Z常说的Model,再加上控制器Control本nQ就构成?jin)MVC模式。实践证明,MVC模式为大型程序的开发及(qing)l护提供?jin)巨大的便利?</div> <div>其实QMVC开始ƈ不是为Web应用E序提出的模式,传统的MVC要求M其状态变化通报lVQ但׃Web览器工作在典型的拉模式而非推模式,很难做到q一炏V因此有些h又将用于Web应用的MVCUC为MVC2。正如上面所提到的MVC是一U模式,当然可以有各U不同的具体实现Q包括?zhn)自己可以实C个体现MVC思想的程序框ӞStruts是一U具体实现MVC2的程序框架。它的大致结构如图三所C:(x) </div> <div><img src="http://tech.ccidnet.com/col/attachment/2004/8/320190.gif" border="0" alt="" /> </div> <div>图三 </div> <div>图三基本勑֋Z(jin)一个基于Struts的应用程序的l构Q从左到叻I分别是其表示层(viewQ、控制层(controller)、和模型?Model)。其表示层用Struts标签库构建。来自客L(fng)所有需要通过框架的请求统一由叫ActionServlet的servlet接收QActionServlet Struts已经为我们写好了(jin)Q只要?zhn)应用没有什么特别的要求Q它基本上都能满x(chng)的要求)(j)Q根据接收的h参数和Struts配置(struts-config.xml)中ActionMappingQ将h送给合适的Actiond理,解决p做的问题Q它们共同构成Struts的控制器。Action则是Struts应用中真正干zȝlgQ开发h员(sh)般都要在q里耗费大量的时_(d)它解决的是做什么的问题Q它通过调用需要的业务lgQ模型)(j)来完成应用的业务Q业务组件解决的是如何做的问题,q将执行的结果返回一个代表所需的描l响应的JSPQ或ActionQ的ActionForward对象lActionServlet以将响应呈现l客戗?</div> <div>q程如图四所C:(x) </div> <div><img src="http://tech.ccidnet.com/col/attachment/2004/8/320192.jpg" border="0" alt="" /> </div> <div>囑֛ </div> <div>q里要特别说明一下的是:(x)是Actionq个c,上面已经说到?jin)它是Struts中真正干zȝ地方Q也是值得我们高度x(chng)的地斏V可是,关于它到底是属于控制层还是属于模型层Q存在两U不同的意见Q一U认为它属于模型层,如:(x)《JSP Web~程指南》;另一些则认ؓ(f)它属于控制层如:(x)《Programming Jakarta Struts》、《Mastering Jakarta Struts》和《Struts Kick Start》等认ؓ(f)它是控制器的一部分Q还有其他一些书如《Struts in Action》也要避免将业务逻辑攑֜ActioncMQ也是_(d)?中Action后的括号中的内容应该从中UdQ但实际中确有一些系l将比较单的且不打算重用的业务逻辑攑֜Action中,所以在图中q是q样表示。显?dng)业务对象从Action分离出来后有利于它的重用Q同时也增强?jin)应用程序的健壮性和设计的灵zL。因此,它实际上可以看作是Controller与Model的适配器,如果要把它归于那一部分Q笔者更們֐于后一U看法,卛_是Controller的一部分Q换句话_(d)它不应该包含q多的业务逻辑Q而应该只是简单地攉业务Ҏ(gu)所需要的数据q传递给业务对象。实际上Q它的主要职责是Q?</div> <div></font><font size="3">校验前提条g或者声?</div> <div></font><font size="3">调用需要的业务逻辑Ҏ(gu) </div> <div></font><font size="3">(g)或处理其他错误 </div> <div></font><font size="3">路由控制到相兌?</div> <div>上面q样单的描述Q初学者可能会(x)感到有些难以接受Q下面D个比较具体的例子来进一步帮助我们理解。如Q假设,我们做的是个?sh)子商务E序Q现在程序要完成的操作Q务是提交定单q返回定单号l客Pq就是关于做什么的问题Q应该由Actioncd成,但具体怎么获得数据库连接,插入定单数据到数据库表中Q又怎么从数据库表中取得q个定单P一般是自增数据列的数据Q,q一pd复杂的问题,q都是解x(chng)么做的问题Q则应该׃个(假设名ؓ(f)orderBoQ业务对象即Model来完成。orderBo可能用一个返回整型值的名ؓ(f)submitOrder的方法来做这件事QAction则是先校验定单数据是否正,以免常说的垃圾进垃圾出;如果正确则简单地调用orderBo的submitOrderҎ(gu)来得到定单号Q它q要处理在调用过E中可能出现M错误Q最后根据不同的情况q回不同的结果给客户?</div> <div><strong>二、ؓ(f)什么要使用Struts框架</strong> </div> <div>既然本文的开始就说了(jin)Q自己可以徏q种框架Qؓ(f)什么要使用Struts呢?我想下面列D的这些理由是显而易见的Q首先,它是建立在MVCq种公认的好的模式上的,Struts在M、V和C上都有涉?qing),但它主要是提供一个好的控制器和一套定制的标签库上Q也是说它的着力点在C和V上,因此Q它天生有MVC所带来的一pd优点Q如Q结构层ơ分明,高可重用性,增加?jin)程序的健壮性和可׾~性,便于开发与设计分工Q提供集中统一的权限控制、校验、国际化、日志等{;其次Q它是个开源项目得C(jin)包括它的发明者Craig R.McClanahan在内的一些程序大师和高手持箋(hu)而细?j)的呉|Qƈ且经受了(jin)实战的检验,使其功能来强大,体系也日d善;最后,是它对其他技术和框架昄出很好的融合性。如Q现在,它已l与tiles融ؓ(f)一体,可以展望Q它很快׃(x)与JSF{融?x)在一赗当?dng)和其他Q何技术一P它也不是十全十美的,如:(x)它对cd一些属性、参数的命名昑־有些随意Q给使用带来一些不便;q有如ActioncexecuteҎ(gu)的只能接收一个ActionForm参数{。但瑕不掩瑜Q这些没有媄(jing)响它被广泛用?</div> <div><strong>三、Struts的安装与基本配置</strong> </div> <div>我们主要针对Struts1.1版本q行讲解Q这里假定读者已l配|好j(lu)avaq行环境和相应的Web容器Q本文例子所使用的是j2sdk和Tomcat4.1.27。下面,采用类gstep by step的方式介l其基础部分?</div> <div><em>安装Struts</em> </div> <div>到http://jakarta.apache.org/ 下蝲Struts的安装文Ӟ本文例子使用的是1.1版?</div> <div>­</div> <div>接下来?zhn)要进行如下几个步骤来完成安装Q?</div> <div>1、解压下载的安装文g到?zhn)的本地硬?</div> <div>2、生成一个新的Web应用Q假设我们生成的应用E序的根目录?Webapps/mystruts目录。在server.xml文g中ؓ(f)该应用新Z个别名如/mystruts </div> <div>3、从W?步解压的文g中拷贝下列jar文g?Webapps/mystruts/WEB-INF/lib目录Q主要文件有如下一些?</div> <div>­</div> <div></font></div> <div>­</div> <div><font size="3">4、创Z个web.xml文gQ这是一个基于servlet的Web应用E序都需要的部v描述文gQ一个Struts Web应用Q在本质上也是一个基于servlet的Web应用Q它也不能例外?</div> <div>­</div> <div>Struts有两个组件要在该文g中进行配|,它们是:(x)ActionServlet和标{ֺ。下面是一个配|清单:(x) </div> <div>­</div> <div></font></div> <div>­</div> <div><font size="3">上面我们在web.xml中完成了(jin)对servlet和标{ֺ的基本配|,而更多的框架lg要在struts-config.xml中进行配|:(x) </div> <div>5、创Z个基本的struts-config.xml文gQƈ把它攑֜/Webapps/mystruts/WEB-INF/目录中,该文件是ZStruts应用E序的配|描q文Ӟ它将MVCl构中的各组件结合在一P开发的q程中会(x)不断对它q行充实和更攏V在Struts1.0Ӟ一个应用只能有一个这L(fng)文gQ给分工开发带来了(jin)一些不便,在Struts1.1Ӟ可以有多个这L(fng)文gQ将上述~点克服?jin)。需在该文g中配|的lg有:(x)data-sources</font></div> <div><font size="3">配置清单如下Q?</font></div> <div><font size="3">到此为止Q我们已l具备了(jin)完成一个最单Struts应用的所需的各U组件。前面已l提刎ͼ在开发过E中我们?x)不断充实和修改上面两个配置描述文g。下面我们将实际做一个非常简单的应用E序来体验一下Struts应用开发的真实q程Q以期对其有一个真实的认识。在完成基础部分的介l后Q笔者会(x)l出一些在实际开发中l常用到而又让初学者感到有些难度的实例。最后,?x)介lStruts与其他框架的关系?qing)结合它们生成应用程序的例子?</font></div> <img src ="http://www.aygfsteel.com/Crying/aggbug/141924.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/Crying/" target="_blank">Crying</a> 2007-09-01 14:37 <a href="http://www.aygfsteel.com/Crying/articles/141924.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ԭ</a>| <a href="http://" target="_blank">̨</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ĵʡ</a>| <a href="http://" target="_blank">Ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">˼</a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">կ</a>| <a href="http://" target="_blank">ͤ</a>| <a href="http://" target="_blank">Ͻ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʯɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ˮ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">̨</a>| <a href="http://" target="_blank">֬</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>