junit比这强多了,到时也给俺们讲讲!
解决方案 »
- frame中获取session问题
- eclipse已经成功添加了tomcat7.0服务,但是删除了之后再添加就没法手动添加7.0服务器了
- 小错误求助
- Hibrnate createSQLQuery使用失败!!!
- dom4j对xml进行schema验证的问题.
- ServletContextListener得到ServletContext?
- 很简单的问题啊 帮我看看啊,偶是初学者啊
- soap传送二进制附件问题求解,253...好心人帮帮我吧,头痛中。
- weblogic 8.1 在哪里修改调度池的容量?????????????
- 配置jdom的问题!急急急
- 如何在weblogic中取得参数值。。。。(在线等侯。。。)
- jboss对ejb-ql支持问题,100分
但是我使用的RESIN服务器一旦JAVAC编译完成类改变整个APPLICATION就重启,所以效果不好
package com.jingjian.tcmms;import com.jingjian.tcmms.*;
import com.jingjian.tcmms.Util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;public class Debug extends HttpServlet
{
static final private String CONTENT_TYPE = "text/html; charset=GBK"; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{ response.setContentType(CONTENT_TYPE); ////调试代码开始 System.out.println("hello world"); ////调试代码结束 }
}
<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.sql.*,java.util.*,java.io.*,com.jingjian.tcmms.*,com.jingjian.tcmms.Util.*" %>
<%@include file="auth_include.jsp"%>
<%
String code="";
code=request.getParameter("code");
if(code==null) code="";%>
<html>
<head>
<link rel=STYLESHEET type="text/css" href="../other/style.css">
<html>
<head>
<title>
调试
</title>
<script src="../js/common.js"></script>
</head>
<body>
<form action=debug.jsp method=post>
<center>
调试JAVA代码:<br>
<textarea name=code cols=80 rows=20><%=code%></textarea>
<br>
<input type=submit value="运行调试代码">
</center>
</form>
<%
if(code==null) return;
String filename=this.getServletContext().getRealPath("/WEB-INF/classes/com/jingjian/tcmms/")+"Debug.java";
File file=new File(filename);
if(!file.exists()) out.println("模板文件"+filename+"不存在!"); java.io.FileInputStream fis=new java.io.FileInputStream(file);
byte[] c=new byte[(int)file.length()];
fis.read(c);
fis.close(); String content=new String(c,"GBK");
int pos1=content.indexOf("////调试代码开始"),pos2=content.indexOf("////调试代码结束");
if(pos1<0||pos2<0) {out.println("模板文件错误!");}
else
{ pos1+="////调试代码开始".length();
FileWriter fw=new FileWriter(file);
fw.write(content.substring(0,pos1)+"\r\n\r\n");
fw.write(code+"\r\n\r\n ");
fw.write(content.substring(pos2));
fw.close();
} try
{
out.println("<hr>");
Runtime r=Runtime.getRuntime();
String classpath=getServletContext().getRealPath("/WEB-INF/classes")+";"+getServletContext().getRealPath("/WEB-INF/lib/servlet.jar");
String cmd="javac -classpath "+classpath+" "+filename;
System.out.println("编译调试指令:"+cmd);
out.println("编译调试指令:"+cmd+"<br>");
java.lang.Process p=r.exec(cmd);
DataInputStream dis=new java.io.DataInputStream(p.getInputStream());
out.println("<h3><font color=blue>编译调试指令返回结果:</font></h3><pre>");
byte buf[]=new byte[512];
int readed=0;
while((readed=dis.read(buf))>-1) out.print(Util.replace(new String(buf,0,readed,"GBK"),"<","<"));
out.println("</pre>");
out.println("<h3>成功编译调试指令。</h3>"); out.println("<h3><font color=blue>调试指令返回结果:</font></h3><pre>");
out.println("<hr>");
this.getServletContext().getRequestDispatcher("/servlet/com.jingjian.tcmms.Debug").include(request,response);
out.println("<hr>");
}
catch(Exception e) {out.println("<h2>执行命令出错!</h2>");e.printStackTrace(new PrintWriter(out));e.printStackTrace();}%>
</body>
</html>
单个的测试类我都会写,action类用StrutsTestCase,bean类用junit
我觉得action类可以写通用的,不过这几天很忙没时间去做