📄 utility.java
字号:
/*
* 创建日期 2005-8-28
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
package com.publish.jxc.charpter9;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Administrator
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public final class Utility {
public final static String Users_XML_File = "data\\users.xml";
public final static String Actions_XML_File = "data\\actions.xml";
public static String outPrintPage(String strInfo)
{
String outText = "";
outText += "<%@ page contentType='text/html; charset=gb2312' %>";
outText += "<script language='javascript'>";
outText += "alert('" + strInfo + "');";
outText += "history.go(-1);";
outText += "</script>";
return outText;
}
public static String outPrintPage(String strInfo, String strUrl)
{
String outText = "";
outText += "<%@ page contentType='text/html; charset=gb2312' %>";
outText += "<script language='javascript'>";
outText += "alert('" + strInfo + "');";
outText += "window.location.href='" + strUrl +"';";
outText += "</script>";
return outText;
}
public static String UnicodeToChinese(String s)
{
try
{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
//catch(UnsupportedEncodingException e)
catch(Exception e)
{
return s;
}
}
public static String ChineseToUnicode(String s)
{
try
{
if(s==null || s.equals(""))
return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
//catch(UnsupportedEncodingException e)
catch(Exception e)
{
return s;
}
}
public static String toHTMLString(String in)
{
StringBuffer out = new StringBuffer();
for(int i=0; in!=null && i<in.length(); i++)
{
char c = in.charAt(i);
if (c == '\'')
out.append("'");
else if (c == '\"')
out.append(""");
else if (c == '<')
out.append("<");
else if (c == '>')
out.append(">");
else if (c == '&')
out.append("&");
else if (c == ' ')
out.append(" ");
else if (c == '\n')
out.append("<br/>");
else
out.append(c);
}
return out.toString();
}
public static void forwardToErrorPage(HttpServletRequest req, HttpServletResponse res)
{
try
{
RequestDispatcher rd = req.getRequestDispatcher(res.encodeURL("error.jsp"));
rd.forward(req, res);
}
catch(IOException e)
{
e.printStackTrace();
}
catch(ServletException e)
{
e.printStackTrace();
}
}
public static void forwardToSpecialPage(HttpServletRequest req, HttpServletResponse res, String url)
{
try
{
RequestDispatcher rd = req.getRequestDispatcher(res.encodeURL(url));
rd.forward(req, res);
}
catch(IOException e)
{
e.printStackTrace();
}
catch(ServletException e)
{
e.printStackTrace();
}
}
public static String getUserManagerPageSection(String strOperation, String contextPath, String requestUrl)
{
String strOut = "<br><table align=center border=0 cellpadding=0 cellspacing=2 width=\"95%\" >";
strOut += "<tbody><tr valign=center><td align=middle><br><table border=0 cellpadding=0 cellspacing=0><tr><td>";
String str;
if (strOperation.equals("addnew"))
{
str = "<input class=stbtm name=update onClick=\"javascript:if (checkform2()==false);\" type=button value=\"更新记录\">";
}
else
{
if(strOperation.equals("modi"))
{
str = "<input class=stbtm name=update onClick=\"javascript:if (checkform()==false);\" type=button value=\"更新记录\">";
}
else
{
str = "<input class=stbtm type=\"button\" name=\"Button\" value=\"新 增\" onClick=\"javascript:window.location.href='" + requestUrl + "?act=addnew';\">";
}
}
strOut += str;
strOut += " </td>";
if(!strOperation.equals("show"))
{
strOut += "<td><input class=stbtm type=\"button\" name=\"Button\" value=\"返 回\" onClick=\"javascript:window.location.href='" + requestUrl + "';\"> </td>";
}
strOut += "<td><input class=stbtm type=\"button\" name=\"Button\" value=\"返回上页\" onClick=\"javascript:window.location.href='" + contextPath + "/pages/admin/index.jsp';\">";
strOut += "</td></tr></table></td></tr></table><p> </p>";
return strOut;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -