Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

why my struts can not work?

Posted on 2004-08-12
13
Medium Priority
?
1,559 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Read on to get a few ideas on how to promote your next corporate event.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

704 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