lodable.jsp
<html:form action="DemoS" method="POST" focus="" >
Program Name :
<html:select property="airline_name" styleId = "tempId" onchange="onAirlineChange()" >
<html:options collection="airline_name" property="value" labelProperty="key" />
</html:select> <br/>
PART NUMBER
<input type="text" name="part_no"id="part_number">
YEAR
<select name="year" id="year" style="width:200px">
<option value="13">2013</option>
<option value="14">2014</option>
<option value="15">2015</option>
</select>
<input type="submit" name="Lodable" value ="OK">
</html:form>
<html:errors/>
DemoForm.java
public class DemoForm extends ValidatorForm{
private String airline_name;
private String part_no;
private String year;
public String getAirline_name() {
return airline_name;
}
public void setAirline_name(String airline_name) {
this.airline_name = airline_name;
}
public String getPre_part_no() {
return pre_part_no;
}
public void setPre_part_no(String pre_part_no) {
this.pre_part_no = pre_part_no;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
ActionErrors errors=new ActionErrors();
if(getPart_no()==null ||getPart_no().length()<1)
{
errors.add("part_no",new ActionMessage("errors.required","part_no"));
}
if(getYear()==null ||getYear().length()<1)
{
errors.add("Year",new ActionMessage("errors.required","Year"));
}
}
}
Struts-config.xml
的摘录:
<form-beans>
<form-bean name="DemoForm" type="com.me.form.DemoForm" scope="session" />
<form-beans/>
<action-mappings>
<action input="/pages/Lodable.jsp" parameter="method" name="DemoForm" path="/DemoS" scope="session" type="com.woi.action.DemoS" validate="true">
<forward name="lodable" path="/pages/Lodable.jsp" />
<forward name="save" path="/pages/success.jsp"></forward>
<forward name="fail" path="/pages/fail.jsp"></forward>
</action>
<action-mappings/>
收集:
public Map<String,String> airline_name= new HashMap<String,String>();
airline_name.put("niraj.deshmukh","template1 ");
airline_name.put("user1","template1 ");
airline_name.put("user2","template2 ");
airline_name.put("user3","template3 ");
request.setAttribute("airline_name", airline_name);
例外:
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean under name airline_name
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:585)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1083)
org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:295)
org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1027)
org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:374)
org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:995)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:198)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
答案 0 :(得分:1)
您没有正确指定操作的路径,应该是
<html:form action="/DemoS"
答案 1 :(得分:0)
检查你是否为formBean类或actionclass创建了构造函数。如果你创建了构造函数,jspcompler会给出如下错误:javax.servlet.jsp.JspException:异常创建类ProductFB的bean。
答案 2 :(得分:0)
以前我没有提到索引页面导航到的页面的正确路径,我使用了jsp:forward
标记
我之前使用过的标签
<jsp:forward page="/faces/views/prime.xhtml"></jsp:forward>
我将其更改为c:redirect
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Index</title>
</head>
<body>
<c:redirect url="/views/prime.xhtml"></c:redirect>
</body>
</html>
问题解决了。