自己弄的一个Struts1实例,总是访问不到action 求大侠指点指点
没事写的一个struts1实例 求大侠指点下 总是访问不到action 配置什么的都没找到原因
话不多说 看效果
jsp 界面:
<form action="loginAction.do" method="post" id="form1">
用户名:<input type="text" name="userName"/>
密码:<input type="password" name="passWord"/><br/>
<input type="submit" value="确定"/>
</form>
web.xml
<servlet>
<servlet-name>struts1</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>struts1</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
struts-config.xml界面
<struts-config>
<form-beans>
<form-bean name="userBean" type="com.zjj.struts1.bean.UserBean"></form-bean>
</form-beans>
<action-mappings>
<action path="/loginAction" name="userBean" type="com.zjj.struts1.action.LoginAction" >
<forward name="success" path="/success.jsp"></forward>
<forward name="error" path="/error.jsp"></forward>
</action>
</action-mappings>
</struts-config>
action界面
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
ServletRequest request, ServletResponse response) throws Exception {
UserBean userForm = (UserBean) actionForm;
String un = userForm.getUserName();
String pw = userForm.getPassWord();
System.out.println("username="+un);
System.out.println("password="+pw);
return actionMapping.findForward("success");
}
------解决方案--------------------struts的配置文件中用/*代替*do
------解决方案--------------------你的web.xml配置不完整,所以找不到action
------解决方案--------------------web.xml中没有配置struts1
------解决方案--------------------java 的 action 继承有没有问题?dispatchaction