
搞成一个方法,往里面传参数,根据参数返回不同的连接字符串就可以了;
public string GetConnection(string str_value)
{
if (str_value=='SQL')
{//SQL连接字符串}
else
if (str_value=='MySQL')
{//MySQL连接字符串}
}
前面放个 label, text为空。
然后 后台代码 把取出的 数据, 用 lu li 写好。 付给labelText 就好。
先写个lu li的例子,然后把里面的数据换成活的就好了。
比如 循环数据集。 最好用, StringBuilder。 不要直接用String 接。
StringBuilder str = new StringBuilder 这样 如
DataSet ds = ;
strAppend("<lu>");
for(int i =0;i<dstable[0]RowsCount;i++)
{
strAppend("<li>"+dstable[0]Rows[i]["列名"]+"</li>") ;
}
strAppend("</lu>");
labelText=strToString();
手写的,可能大小写没区分好。挺简单的,你注意下就好。
根据数据库字段动态的生成一个页面,利用Filter和定制Response,把服务器返回的JSP响应输出到我们自己的Response中,就可以将响应快速写入Html文件,然后再发送给客户。
import javaio;
import javaxservlet;
import javaxservlet>
import javautilCalendar;
public class CacheFilter implements Filter {
ServletContext sc;
FilterConfig fc;
long cacheTimeout = LongMAX_VALUE;
public void doFilter(ServletRequest req,
ServletResponse res,
FilterChain chain)
throws IOException, ServletException {
>
(>
>
(>
// check if was a resource that shouldn't be cached
String r = scgetRealPath("");
String path =
fcgetInitParameter(requestgetRequestURI());
if (path!= null && pathequals("nocache")) {
chaindoFilter(request, response);
return;
}
path = r+path;
String id = requestgetRequestURI() +
requestgetQueryString();
File tempDir = (File)scgetAttribute(
"javaxservletcontexttempdir");
// get possible cache
String temp = tempDirgetAbsolutePath();
File file = new File(temp+id);
// get current resource
if (path == null) {
path = scgetRealPath(requestgetRequestURI());
}
File current = new File(path);
try {
long now =
CalendargetInstance()getTimeInMillis();
//set timestamp check
if (!fileexists() || (fileexists() &&
currentlastModified() > filelastModified()) ||
cacheTimeout < now - filelastModified()) {
String name = filegetAbsolutePath();
name =
namesubstring(0,namelastIndexOf("/"));
new File(name)mkdirs();
ByteArrayOutputStream baos =
new ByteArrayOutputStream();
CacheResponseWrapper wrappedResponse =
new CacheResponseWrapper(response, baos);
chaindoFilter(req, wrappedResponse);
FileOutputStream fos = new FileOutputStream(file);
foswrite(baostoByteArray());
fosflush();
fosclose();
}
} catch (ServletException e) {
if (!fileexists()) {
throw new ServletException(e);
}
}
catch (IOException e) {
if (!fileexists()) {
throw e;
}
}
FileInputStream fis = new FileInputStream(file);
String mt = scgetMimeType(requestgetRequestURI());
responsesetContentType(mt);
ServletOutputStream sos = resgetOutputStream();
for (int i = fisread(); i!= -1; i = fisread()) {
soswrite((byte)i);
}
}
public void init(FilterConfig filterConfig) {
thisfc = filterConfig;
String ct =
fcgetInitParameter("cacheTimeout");
if (ct != null) {
cacheTimeout = 601000LongparseLong(ct);
}
thissc = filterConfiggetServletContext();
}
public void destroy() {
thissc = null;
thisfc = null;
}
}
以上就是关于C#怎么动态生成各种数据库的连接字符串全部的内容,包括:C#怎么动态生成各种数据库的连接字符串、我在HTML中写了一个<ul><li>标签 ,怎麼把数据库的数据动态动态生成到标签里面 C#、如何根据数据库字段动态的生成一个页面等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)