新闻添加生成html页遇到的问题
在本机jdk1.5+tomcat5调试通过了,但是放到服务器就出错,服务器是jdk1.4+tomcat3
就出错.
Error: 500
Location: /yx/xxgl/document/news_save.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile class for JSPC:\tomcat\work\localhost_8080\_0002fyx_0002fxxgl_0002fdocument_0002fnews_0005fsave_0002ejspnews_0005fsave_jsp_3.java:150: class java.lang.String ?????? replaceAll(java.lang.String, java.lang.String)?
okfile=okfile.replaceAll( "ArticleTitle ",title);
^
C:\tomcat\work\localhost_8080\_0002fyx_0002fxxgl_0002fdocument_0002fnews_0005fsave_0002ejspnews_0005fsave_jsp_3.java:151: class java.lang.String ?????? replaceAll(java.lang.String, java.lang.String)?
okfile=okfile.replaceAll( "ArticleContent ",content);
^
C:\tomcat\work\localhost_8080\_0002fyx_0002fxxgl_0002fdocument_0002fnews_0005fsave_0002ejspnews_0005fsave_jsp_3.java:152: class java.lang.String ?????? replaceAll(java.lang.String, java.lang.String)?
okfile=okfile.replaceAll( "writer ",writer);
^
C:\tomcat\work\localhost_8080\_0002fyx_0002fxxgl_0002fdocument_0002fnews_0005fsave_0002ejspnews_0005fsave_jsp_3.java:153: class java.lang.String ?????? replaceAll(java.lang.String, java.lang.String)?
okfile=okfile.replaceAll( "fromsite ",nfrom);
^
C:\tomcat\work\localhost_8080\_0002fyx_0002fxxgl_0002fdocument_0002fnews_0005fsave_0002ejspnews_0005fsave_jsp_3.java:154: class java.lang.String ?????? replaceAll(java.lang.String, java.lang.String)?
okfile=okfile.replaceAll( "dateandtime ",pathdate);}
^
C:\tomcat\work\localhost_8080\_0002fyx_0002fxxgl_0002fdocument_0002fnews_0005fsave_0002ejspnews_0005fsave_jsp_3.java:172: class java.util.Calendar ?????? getTimeInMillis() ????
String filename = String.valueOf(calendar.getTimeInMillis()) + ".html ";
^
???C:\tomcat\work\localhost_8080\_0002fyx_0002fxxgl_0002fdocument_0002fnews_0005fsave_0002ejspnews_0005fsave_jsp_3.java ???????????? API???-deprecation?????????????
6 ???, 1 ???
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:247)
at org.apache.jasper.runtime.JspServlet.loadJSP(JspServlet.java:413)
at org.apache.jasper.runtime.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:149)
at org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:161)
at org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:261)
at org.apache.jasper.runtime.JspServlet.service(JspServlet.java:369)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:160)
at org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338)
at java.lang.Thread.run(Unknown Source
----------------------------------
代码:
<%@ page contentType= "text/html;charset=gb2312 " language= "java "%>
<%@ include file= "../../conn/accessconn.jsp "%>
<%@ include file= "../../conn/common.jsp "%>
<%
//当前日期
SimpleDateFormat sdate = new SimpleDateFormat( "yyyy-MM-dd ");
java.util.Date date=new java.util.Date();
String pathdate= sdate.format(date);
// out.write(pathdate);
Statement stmt=null,stmt1=null;
ResultSet rs=null,nrs=null;
String sql=null,sql1=null;
String newsid=request.getParameter( "newsid ");
String nfrom=request.getParameter( "nfrom ");
if (nfrom!=null) nfrom= new String(nfrom.getBytes( "ISO-8859-1 "), "GB2312 ");
String title=request.getParameter( "title ");
if (title!=null) title= new String(title.getBytes( "ISO-8859-1 "), "GB2312 ");
String content=request.getParameter( "newstext ");
if (content!=null) content= new String(content.getBytes( "ISO-8859-1 "), "GB2312 ");
String writer=request.getParameter( "writer ");
if (writer!=null) writer= new String(writer.getBytes( "ISO-8859-1 "), "GB2312 ");
String classid=request.getParameter( "classselect ");
if (classid!=null) classid= new String(classid.getBytes( "ISO-8859-1 "), "GB2312 ");
//out.println(classid);
String boardid=request.getParameter( "boardselect ");
if (boardid!=null) boardid= new String(boardid.getBytes( "ISO-8859-1 "), "GB2312 ");
//out.println(boardid);
String demoid=request.getParameter( "demo ");
if (demoid!=null) demoid= new String(demoid.getBytes( "ISO-8859-1 "), "GB2312 ");
stmt=conn.createStatement();
sql= "select demohtml from demo where demoID= "+demoid;
rs=stmt.executeQuery(sql);
String okfile= " ";
if(rs.next()){
okfile=rs.getString( "demohtml ");
//out.println(pencat);
okfile=okfile.replaceAll( "ArticleTitle ",title);
okfile=okfile.replaceAll( "ArticleContent ",content);
okfile=okfile.replaceAll( "writer ",writer);
okfile=okfile.replaceAll( "fromsite ",nfrom);
okfile=okfile.replaceAll( "dateandtime ",pathdate);}
//out.println(okfile);
//在html下生成当天日期的文件夹
String path= "yx/html "+ "\\ "+pathdate;
String sWebRootPath = request.getRealPath(path);
java.io.File myFilePath =new java.io.File(sWebRootPath);
if(!myFilePath.exists())
{
myFilePath.mkdir();
}
Calendar calendar = Calendar.getInstance();
String filename = String.valueOf(calendar.getTimeInMillis()) + ".html ";
String filepath= request.getRealPath( "yx/html ")+ "\\ "+pathdate+ "\\ "+filename;//生成的html文件保存路径
//out.write(filepath);
FileOutputStream fileoutputstream = new FileOutputStream(filepath);//建立文件输出流
byte tag_bytes[] = okfile.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();
//添加数据库
String fileline=pathdate+ "\\ "+filename;
stmt1=conn.createStatement();
sql= "select * from newsdb where ID= "+newsid;
nrs=stmt1.executeQuery(sql);
if (nrs.next()){
sql1= "update newsdb set title= ' "+title+ " ',content= ' "+content+ " ',writer= ' "+writer+ " ',nfrom= ' "+nfrom+ " ' ,fileline= ' "+fileline+ " 'where ID= "+newsid;
stmt1.executeUpdate(sql1);
}else{
sql1= "insert into newsdb(title,content,nfrom,dateandtime,fileline,writer,classid,boardid) ";
sql1=sql1+ "values( ' "+title+ " ', ' "+content+ " ', ' "+nfrom+ " ', ' "+pathdate+ " ', ' "+fileline+ " ', ' "+writer+ " ', ' "+classid+ " ', ' "+boardid+ " ') ";
//out.println(sql1);
stmt1.executeUpdate(sql1);
}
%>
<div align= "center ">
<table border= "0 " cellspacing= "1 " width= "50% " bgcolor= "#000000 " bordercolorlight= "#11B1FF " bordercolordark= "#F0F8FF " cellpadding= "0 ">
<tr bgcolor= "#000066 ">
<td width= "100% " height= "20 ">
<p align= "center "> <font color= "#FFFFFF "> <b> 添加 </b> 文 <b> 章成功 </b> </font>
</td>
</tr>
<tr>
<td width= "100% " bgcolor= "#FFFFFF ">
<p align= "left "> <br>
其文件名为: <%=filename%> <br>
文件标题为: <%=title%> </p>
<p align= "center "> 是否继续添加? <br>
<br>
<a href= "news_add.jsp "> 是 </a> <a href= "lb_list.jsp "> 否 </a> <br>
<br>
</p>
</td>
</tr>
</table>
</div>
[解决办法]
还用问吗?环境都不一样了,怎么通过呢?
把环境改成一样不就得了。
如果服务器环境不能改,把你的开发机环境改成和服务器一样,然后再修改代码。
[解决办法]
up
[解决办法]
okfile=okfile.replaceAll( "ArticleTitle ",title);
好象tomcat4.X前,不支持replaceAll
自己写一个替换字符串的方法
[解决办法]
是这样啦,偶曾经因为换了tomcat和jdk的版本,将整个程序全部检查修改,痛苦,不都说一次编译,到处执行,哎!如果换weblogic好象还有细微的差别,如:return等等
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html