转码: byte[] temp;
String tempdealresult=request.getParameter("dealresult") ;
temp=tempdealresult.getBytes("iso8859-1");
String dealresult=new String(temp);
String tempdealresult=request.getParameter("dealresult") ;
temp=tempdealresult.getBytes("iso8859-1");
String dealresult=new String(temp);
麻烦了!
package attributeservlet;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;public class AttributeServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session=request.getSession();
String name= request.getParameter("attrib_name");
if (name == null) {
name = "";
}
String value = request.getParameter("attrib_value");
if (value == null) {
value = "";
}
String remove = request.getParameter("attrib_remove");
if (remove == null) {
remove = "";
} if(remove!=null&&remove.equals("on")){
session.removeAttribute(name);
}else{
if(name!=null&&name.length()>0&&(value!=null)&&value.length()>0){
session.setAttribute(name,value);
}
} response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<meta http-equiv=\"Pragma\" content=\"no-cache\">" );
out.println("<head><title>Session AttributeServlet</title></head>");
out.println("<body bgcolor=\"#00ffff\">");
out.println("<h1>Session Attributes</h1>"); out.println("Enter name and value of an attribute"); //HAVE WARNING
String url=response.encodeUrl("/AttribueServlet/attributeservlet");
out.println("<FORM ACTION=\"" +url+"\" METHOD=\"GET\">"); out.println("<br>");
out.println("Name");
out.println("<INPUT TYPE=\"text\" SIZE=\"10\" NAME=\"attrib_name\">"); out.println("Value");
out.println("<INPUT TYPE=\"text\" SIZE=\"10\" NAME=\"attrib_value\">"); out.println("<br>");
out.println("<br><input type=\"checkbox\" NAME=\"attrib_remove\">Remove");
out.println("<br><br>");
out.println("<INPUT TYPE=\"submit\" NAME=\"update\" VALUE=\"Update\">");
out.println("</form>"); out.println("<hr>");
out.println("Atrributes in this Session"); Enumeration e=session.getAttributeNames();
while(e.hasMoreElements()){
String att_name=(String)e.nextElement();
String att_value=(String) session.getAttribute(att_name); out.println("<br><b>Name:</b>");
out.println(att_name);
out.println("<b>Value:</b>");
out.println(att_value);
} out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</body></html>");
out.close();
}
//Clean up resources
public void destroy() {
}
}
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class ExamineOperator extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session=request.getSession();
byte[] temp;
String tempdealresult="";
if (request.getParameter("attrib_name")!=null)
tempdealresult=request.getParameter("attrib_name");
temp=tempdealresult.getBytes("iso8859-1");
String name=new String(temp);
}
}