Solved

why my struts can not work?

Posted on 2004-08-12
13
1,549 Views
Last Modified: 2008-01-09
hi,experts,this is my first struts,but it will create error,like this:

500 Servlet Exception
javax.servlet.jsp.JspException: Exception creating bean of class com.beltino.communitymedical.UserForm:
{1}
      at org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:563)
      at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:520)
      at _jsp._createuser__jsp._jspService(/createUser.jsp:16)
      at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
      at com.caucho.jsp.Page.pageservice(Page.java:571)
      at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:155)
      at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:211)
      at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
      at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
      at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
      at com.caucho.server.port.TcpConnection.run(TcpConnection.java:331)
      at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:464)
      at com.caucho.util.ThreadPool.run(ThreadPool.java:408)
      at java.lang.Thread.run(Thread.java:534)


--------------------------------------------------------------------------------
Resin-3.0.8 (built Tue, 08 Jun 2004 02:25:40 PDT)

--------------------------------------------
this is my jsp page:(createUser.jsp)

<%@ page contentType="text/html;charset=gb2312"%>
<%@ taglib uri="/struts-logic" prefix="logic" %>
<%@ taglib uri="/struts-bean" prefix="bean" %>
<%@ taglib uri="/struts-html" prefix="html" %>
<html:html locale="true">
<head>
<html:base/>
<title>
<bean:message key="index.title"/>
</title>
</head>
<body>
<h2>careate a new</h2>

<html:errors/>
<html:form action="/createUser.do" method="GET">
  userName:<html:text property="user.userName"/><br/>
  password:<html:password property="user.password" /><br/>
  age:<html:text property="user.age" /><br/>
  <html:submit property="submit"/>
</html:form>
</body>
</html:html>

when i not use <html:form></html:form> this can work and in this page can show "crate a new"

why? thanks for help!
0
Comment
Question by:hgbdelphi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
13 Comments
 

Author Comment

by:hgbdelphi
ID: 11781481
this is my struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
   
    <!-- ========== Data Source Configuration =============================== -->
    <data-sources />
   
    <!-- ========== Form Bean Definitions ================================== -->
    <form-beans>
        <form-bean name="userForm" type="com.beltino.communitymedical.UserForm" />
    </form-beans>
   
    <!-- ========== Global Exception Definitions ============================== -->
    <global-exceptions />
   
    <!-- ========== Global Forward Definitions =============================== -->
    <global-forwards>
        <forward name="userCreated" path="/viewUser.jsp" />
    </global-forwards>
   
    <!-- ========== Action Mapping Definitions =============================== -->
    <action-mappings>
        <action
            attribute="userForm"
            input="/createUser.jsp"
            name="userForm"
            scope="request"
            path="/createUser"
            type="com.beltino.communitymedical.UserAction" />
    </action-mappings>
   
    <!-- ========== Controller Configuration ================================ -->
    <controller />
   
    <!-- ========== Message Resources Definitions ============================ -->
   
    <!-- ========== Plug Ins Configuration ================================= -->
    <message-resources parameter="ApplicationResources"/>
</struts-config>

0
 
LVL 35

Expert Comment

by:TimYates
ID: 11781507
And what's the source for com.beltino.communitymedical.UserForm?
0
 

Author Comment

by:hgbdelphi
ID: 11781621
hi,TimYates ,
UserForm:

package com.beltino.communitymedical;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;

/**
 * @author aus
 */
public class UserForm extends ActionForm {
      private User user=new User();
      
      public void setUserName(String userName){
        user.setUserName(userName);
      }
      
      public String getUserName(){
        return user.getUserName();
      }

      /**
       * @return
       */
      public User getUser() {
            return user;
      }

      /**
       * @param user
       */
      public void setUser(User user) {
            this.user = user;
      }
      
      public void reset(ActionMapping mapping,HttpServletRequest request){
        this.user=new User();
      }
      
      public ActionErrors validate(ActionMapping mapping,HttpServletRequest request){
        ActionErrors errors=new ActionErrors();
        if((user.getUserName()==null) || (user.getPassword().length()<3)){
          errors.add("password:",new ActionError("error.user.password"));
        }
        return errors;
      }

}
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:hgbdelphi
ID: 11781622
UserBean:

package com.beltino.communitymedical;

import com.beltino.util.*;
/**
 * @author aus
 */
public class UserBean {
      
      DBConn dbConn=new DBConn();
      
      public void addUser(User user) throws Exception{
        String sql="";
        sql="insert into TUserRight(RightName,Remark) values('"+user.getUserName()+"','"+user.getPassword()+"')";
        dbConn.executeUpdate(sql);  
      }
      
}
0
 

Author Comment

by:hgbdelphi
ID: 11781627
UserAction:

package com.beltino.communitymedical;

import org.apache.struts.action.*;
import javax.servlet.http.*;
/**
 * @author aus
 */
public class UserAction extends Action{
      public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
        UserForm f=(UserForm)form;
        try{
          UserBean bean=new UserBean();
          bean.addUser(f.getUser());
        }catch(Exception e){
          e.printStackTrace();
        }
        request.setAttribute("User",f.getUser());
        return (mapping.findForward("userCreated"));
      }

}
0
 

Author Comment

by:hgbdelphi
ID: 11781629
User:

package com.beltino.communitymedical;

/**
 * @author aus
 */
public class User {
      public String userName;
      public String password;
      public int age;

      /**
       * @return
       */
      public int getAge() {
            return age;
      }

      /**
       * @return
       */
      public String getPassword() {
            return password;
      }

      /**
       * @return
       */
      public String getUserName() {
            return userName;
      }

      /**
       * @param i
       */
      public void setAge(int i) {
            age = i;
      }

      /**
       * @param string
       */
      public void setPassword(String string) {
            password = string;
      }

      /**
       * @param string
       */
      public void setUserName(String string) {
            userName = string;
      }

}
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11781638
<html:form action="/createUser.do" method="GET">

should be:

<html:form action="/createUser" method="GET">

(I think)
0
 

Author Comment

by:hgbdelphi
ID: 11781693
sorry TimYates ,
when i use <html:form action="/createUser" method="GET">,the error is same!

thanks!
0
 

Author Comment

by:hgbdelphi
ID: 11781707
in consle,error is

the import org.apache.struts cannot be resolved
ActionForm cannot be resolved or is not a valid superclass

i cope some jar in my application's  WEB-INF/lib/
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11781722
> i cope some jar in my application's  WEB-INF/lib/

Make sure you have copied ALL the jars from the struts-blank example into your WEB-INF/lib
0
 

Author Comment

by:hgbdelphi
ID: 11782006
yes,i copy all jar in my web-inf/lib
0
 
LVL 35

Accepted Solution

by:
TimYates earned 50 total points
ID: 11782028
can you list the files?

did you try restarting tomcat after you copied them?
0
 

Author Comment

by:hgbdelphi
ID: 11789441
hi,TimYates,now i can use my struts page,i add struts.jar in eclipse's lib,so it can work,but i don't know why this can work,and the *.jar is already in WEB-INF/lib,but i don't add eclipse's lib,when i add it in eclipse lib ,it can work!


  thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Getting to know the threat landscape in which DDoS has evolved, and making the right choice to get ourselves geared up to defend against  DDoS attacks effectively. Get the necessary preparation works done and focus on Doing the First Things Right.
Let's recap what we learned from yesterday's Skyport Systems webinar.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question