准备写一个MVC架构的小程序,实现的目标是在Face.jsp中输入一串字符,然后在showMiwen.jsp中会把加密后的密文给输出来,结果抛出了org.apache.jasper.JasperException: Cannot find any information on property 'ciphertext' in a bean of type 'xx.JiamiBean'这种异常,希望大家能够帮忙解决一下,先贴代码吧:
这是javaBean文件
package xx;public class JiamiBean {
private String cleartext;
private char[] letter = {'A','B','C','D','E','F','G','H','I','G','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
private int[] wheel1={23,24,25,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22};
private int[] wheel2={7,17,25,16,19,21,9,2,12,10,3,22,4,23,8,11,24,15,18,5,14,20,1,6,0,13};
String ciphertext2 ;
char[] chararr;
private String ciphertext;
public JiamiBean(){}
public JiamiBean(String cleartext){
this.ciphertext=encrypt(cleartext);
}
public String getcleartext() {
return this.cleartext;
}
public void setcleartext(String cleartext) {
this.cleartext = cleartext;
}
private void setciphertext(String ciphertext){
this.ciphertext=ciphertext;
}
private String getciphertext(){
return this.ciphertext;
}
public String encrypt(String str){
chararr=str.toCharArray();
int cl=chararr.length;
char[] mw=new char[cl];
try {
for(int i=0;i<cl;i++){
int j=wheel1[i];
int k=wheel2[j];
mw[i]=letter[k];
}
ciphertext2=arrToString(mw);
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage()+"encrypt");
}
System.out.println(ciphertext2);
return ciphertext2;
} static String arrToString(char[] arr){
StringBuilder jbs=new StringBuilder();
for(char x:arr){
jbs.append(x);
}
return jbs.toString();
}
}这是servlet文件
package xx;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Jiami extends HttpServlet { public Jiami() {
super();
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312");
String cleartext=request.getParameter("cleartext");
System.out.println(cleartext);
JiamiBean jb=new JiamiBean(cleartext);
request.setAttribute("JiamiBean", jb);
RequestDispatcher rd=request.getRequestDispatcher("showMiwen.jsp");
rd.forward(request, response);
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
}这是登陆界面
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Cleartext</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<table>
<form action="Jiami" method="post">
<h2>Input your cleartext in capital letters,you will get your Ciphertext:</h2><br>
<div align="center">
<tr><td><input type="text" name="cleartext" value="123"></td></tr>
<tr>
<td><input type="submit" value="Yes"></td>
<td><input type="reset" value="No"></td>
</tr>
</div>
<div align="center"><img src="cycle.jpg" width="300" height="300"></div>
</form>
</table>
</body>
</html>这是密文显示的界面
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="xx.JiamiBean" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Ciphertext</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<jsp:useBean id="JB" class="xx.JiamiBean" scope="request">
<jsp:setProperty name="JB" property="ciphertext" param="ciphertext"/>
<table align="center">
<h4>密文</h4>
<tr>
<td><textarea cols=50 rows=10>
<jsp:getProperty name="JB" property="ciphertext" ></jsp:getProperty></textarea></td>
</tr>
</table>
</jsp:useBean>
</body>
</html>以下是报的错误:
2011-10-30 11:32:56 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Cannot find any information on property 'ciphertext' in a bean of type 'xx.JiamiBean'
at org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:839)
at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1068)
at org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1124)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1370)
at org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
at org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
at org.apache.jasper.compiler.Generator.generate(Generator.java:3459)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:231)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at xx.Jiami.doPost(Jiami.java:30)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
at java.lang.Thread.run(Thread.java:619)
2011-10-30 11:32:56 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet Jiami threw exception
org.apache.jasper.JasperException: Cannot find any information on property 'ciphertext' in a bean of type 'xx.JiamiBean'
at org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:839)
这是javaBean文件
package xx;public class JiamiBean {
private String cleartext;
private char[] letter = {'A','B','C','D','E','F','G','H','I','G','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
private int[] wheel1={23,24,25,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22};
private int[] wheel2={7,17,25,16,19,21,9,2,12,10,3,22,4,23,8,11,24,15,18,5,14,20,1,6,0,13};
String ciphertext2 ;
char[] chararr;
private String ciphertext;
public JiamiBean(){}
public JiamiBean(String cleartext){
this.ciphertext=encrypt(cleartext);
}
public String getcleartext() {
return this.cleartext;
}
public void setcleartext(String cleartext) {
this.cleartext = cleartext;
}
private void setciphertext(String ciphertext){
this.ciphertext=ciphertext;
}
private String getciphertext(){
return this.ciphertext;
}
public String encrypt(String str){
chararr=str.toCharArray();
int cl=chararr.length;
char[] mw=new char[cl];
try {
for(int i=0;i<cl;i++){
int j=wheel1[i];
int k=wheel2[j];
mw[i]=letter[k];
}
ciphertext2=arrToString(mw);
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println(e.getMessage()+"encrypt");
}
System.out.println(ciphertext2);
return ciphertext2;
} static String arrToString(char[] arr){
StringBuilder jbs=new StringBuilder();
for(char x:arr){
jbs.append(x);
}
return jbs.toString();
}
}这是servlet文件
package xx;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Jiami extends HttpServlet { public Jiami() {
super();
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312");
String cleartext=request.getParameter("cleartext");
System.out.println(cleartext);
JiamiBean jb=new JiamiBean(cleartext);
request.setAttribute("JiamiBean", jb);
RequestDispatcher rd=request.getRequestDispatcher("showMiwen.jsp");
rd.forward(request, response);
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
}这是登陆界面
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Cleartext</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<table>
<form action="Jiami" method="post">
<h2>Input your cleartext in capital letters,you will get your Ciphertext:</h2><br>
<div align="center">
<tr><td><input type="text" name="cleartext" value="123"></td></tr>
<tr>
<td><input type="submit" value="Yes"></td>
<td><input type="reset" value="No"></td>
</tr>
</div>
<div align="center"><img src="cycle.jpg" width="300" height="300"></div>
</form>
</table>
</body>
</html>这是密文显示的界面
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="xx.JiamiBean" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Ciphertext</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<jsp:useBean id="JB" class="xx.JiamiBean" scope="request">
<jsp:setProperty name="JB" property="ciphertext" param="ciphertext"/>
<table align="center">
<h4>密文</h4>
<tr>
<td><textarea cols=50 rows=10>
<jsp:getProperty name="JB" property="ciphertext" ></jsp:getProperty></textarea></td>
</tr>
</table>
</jsp:useBean>
</body>
</html>以下是报的错误:
2011-10-30 11:32:56 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Cannot find any information on property 'ciphertext' in a bean of type 'xx.JiamiBean'
at org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:839)
at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1068)
at org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1124)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1370)
at org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
at org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
at org.apache.jasper.compiler.Generator.generate(Generator.java:3459)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:231)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at xx.Jiami.doPost(Jiami.java:30)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
at java.lang.Thread.run(Thread.java:619)
2011-10-30 11:32:56 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet Jiami threw exception
org.apache.jasper.JasperException: Cannot find any information on property 'ciphertext' in a bean of type 'xx.JiamiBean'
at org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:839)
建议对于get和set方法使用eclise的自动生成比较好
get和set方法的生成规则是set(get)+属性的名称,其中属性名称的第一个字母是大写的
你的全是小写的
getCiphertext()
用自动生成吧
<jsp:setProperty name="JB" property="ciphertext" param="ciphertext"/>
Servlet访问JiamiBean中ciphertext,发现访问不到,就报不存在这个ciphertext
this.ciphertext=encrypt(cleartext);
} 你在构造函数中调用了成员方法encrypt();
试想下,ciphertext能得到东西嘛?
response.setContentType("text/html;charset=gb2312");
String cleartext=request.getParameter("cleartext");
System.out.println(cleartext);
/Struts1 怎么写就可以了
JiamiBean jb=new JiamiBean();
jb.setCiphertext(encrypt(cleartext));
/Struts2
ciphertext=encrypt(cleartext);
request.setAttribute("JiamiBean", jb);
我的是Struts2,我把你的代码弄进去试了一下,可是还是不行啊。你能把servlet中完整的代码贴出来一下吗,谢谢
response.setContentType("text/html;charset=gb2312");
String cleartext=request.getParameter("cleartext");
System.out.println(cleartext);
JiamiBean jb=new JiamiBean(cleartext);request.setAttribute("JiamiBean", jb);
RequestDispatcher rd=request.getRequestDispatcher("showMiwen.jsp");
rd.forward(request, response);
/你这明明就是一个servlet ,怎么是Struts2...
request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312");
String cleartext=request.getParameter("cleartext");
System.out.println(cleartext);
JiamiBean jb=new JiamiBean();
jb.setCiphertext(encrypt(cleartext));
request.setAttribute("JiamiBean", jb);
RequestDispatcher rd=request.getRequestDispatcher("showMiwen.jsp");
rd.forward(request, response);
这样就可以了,还有错再说